HTML forms are created using the
<form> tag, which takes two main attributes:
action specifies the URL of the page that processes the form. It is required. The
method attribute has two possible values:
get. A basic form tag is shown below:
<form method="post" action="Register.cfm"> <!--form fields go here--> </form>
The value of the
method attribute is used to determine 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.firstname.lastname@example.org&pw=foobar&flavor=hardChoc& sprinkles=on&whip=on&container=wafflecone& requests=I+want+a+really+big+cone%21&discount=20%2
You'll notice the file name is followed by a question mark, which is followed by several name-value pairs (e.g,
container=wafflecone) 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.
Files can be uploaded to the server via the file input type. The tag syntax is: <input type="file" name="filename">