Your Form Knows URL Of Previous Page
You have a web page with a recommend form or a form to
request more information. You have links to the form at
various web pages. And you want the form to know which web
page the user came from.
This article shows you how to give the form the URL of the
web page where the link was clicked.
The method I'll show you does not use cookies. And, it does
not use browser-provided referrer information, as that
information is unreliable.
The method does use JavaScript. If the user's browser is not
JavaScript-enabled, the form will not know which link was
clicked. But the form will still work.
Constructing A Link To The Form
On the web pages containing a link to the page with the
form, construct the link this way:
Replace the http://example.com/myform.html URL with the URL
to the web page with the form. Also, replace Click Here with
your link text or image.
The above code constructs a link with a parameter consisting of
the URL of the current web page. A parameter is information
following the ? character in a URL. The parameter, in this
case, will be passed to the web page with the form when the
link is clicked.
Providing The Link Page's URL To The Form
As noted in the previous section, when the link is clicked
to take the browser to the form, the link contains a
parameter consisting of the URL of the web page containing
the link.
When the browser arrives at the web page with the form,
JavaScript extracts the parameter information. To provide
the form with the link URL, the value of a form field is
updated with the parameter information.
For purposes of illustration, let's assume the value being
updated with the parameter information is of a hidden field.
Let's further assume the hidden field's name is linkurl.
When implementing this, change the form field type and name
as appropriate.
First, type the beginning of the form field, like this:
Next, type the JavaScript that will insert the parameter
information:
Last, type the ending of the form field, like this:
To the browser, the hidden field would look something like
this (provided parameter information was available):
If there is no parameter information (the user arrived by a
means other than through one of the special links) or if the
browser is JavaScript-disabled, then no value is printed. To
the browser, it would then appear something like this:
When no value is specified for a form field, the effect is
the same as when value="" is specified.
Form Handling Software
The recommend form suggested at the beginning of the
article can be created with Master Recommend Pro V4.
For information request forms, and many other types
of forms, we recommend our own Master Form V4
Master Form V4 may be the most sophisticated and
flexible form handler on the internet.
The method described above will work with any of our form
handling software that you can install and run from your own
server. Three sections of the WillMaster Products index page
link to lists of software you can run from your own server:
-
The Master Series Software Index
-
WS2 CGI and PHP Software
-
Free Web Site Software
Whatever your need, you'll find powerful software solutions
at Willmaster.com
Will Bontrager
© Bontrager Connection, LLC
Please note:
Articles on this website are presented "as is". However -
If you have a question about a CGI script, HTML, CSS, PHP, or JavaScript
Ask one of our Experts and you'll have your answer!
Click here for details.