HTML forms are created using the
<form> tag, which takes two main attributes:
action specifies the URL of the page that processes the form. The
attribute has two possible values:
get (default value). A form tag example is shown below:
<form>form method="post" action="https://www.webucator.com/course-demos/htm101/process-form.cfm"> <!--form fields go here--> </form>
The value of the
method attribute determines how the form data will be passed to the server.
get is used the data will be appended to the URL as part of a querystring. For example,
if the form is filled out as follows:
When the user submitted the form, the URL for the new page would read (without the line breaks):
Register.email@example.com&pw=foobar&flavor=hardChoc& sprinkles=on&whip=on&container=wafflecone& requests=I+want+a+really+big+cone%21&discount=20%25&submit button=Place+Order
You'll notice the file name is followed by a question mark, which is followed by several name-value pairs (e.g.,
separated by ampersands (
get method is commonly used by search engines, because it allows the resulting page to be bookmarked.
post is used, the name-value pairs are not sent as part of the querystring. Instead they are sent behind the scenes.
This has the advantage of keeping the values hidden from anyone looking over the user's shoulder. Two other advantages of the
post method are:
As a general rule, you should use
post unless you want the user to be able to bookmark or share (e.g., via email) the resulting web page.