Now that you know about creating checkboxes, radio buttons, and submit buttons within a FORM tag, we need to look once more at the METHOD attribute of the FORM tag.
Here is the code from the example from the previous section:
<html> <head> <title>Example Form</title> </head> <body> <form> <p>Choose your favorite type of pet:<br /> <input type="radio" name="pets" value="dog" /> Dog<br /> <input type="radio" name="pets" value="cat" /> Cat<br /> <input type="radio" name="pets" value="bird" /> Bird</p> <p>Choose your favorite color:<br /> <input type="radio" name="colors" value="red" /> Red<br /> <input type="radio" name="colors" value="green" /> Green<br /> <input type="radio" name="colors" value="blue" /> Blue</p> <input type="submit" value="Submit Me, Please" /> </form> </body> </html>
And here is the example displayed.
Make a choice from each group of radio buttons in this example and click the submit button as shown in the following illustration:
Look in the location bar of the browser (where the URL for the current page is displayed), as shown in the following illustration:
You will notice that a question mark (?) has been added to the end of the URL for the current page, and see so-called "name-value pairs" appended onto the end of the URL following the question mark (in the example above, the name-value pairs are "pets=cat"
and "colors=red"
).
When a FORM is submitted, the various form elements in the FORM may be converted into name-value pairs derived from the values of their NAME and VALUE attributes, e.g. NAME=VALUE
. When there is more than one name-value pair in a FORM, the ampersand (&) character is inserted between the pairs. These name-value pairs may be looked at by a script analyzing a FORM.
The text comprised of the question mark followed by name-value pairs in the web browser's location bar is called a "query string".
When a FORM has its METHOD attribute set equal to "get"
(the default value), clicking on the submit button causes the browser to extract all of the chosen name-value pairs from the FORM; these name-value pairs are then converted into a query string which is appended onto the end of the URL in the web browser's location bar.
When a FORM has its METHOD attribute set equal to "post"
, the form information is submitted in a manner which does not need further explanation at this time. With method="post"
If you are utilizing a pre-made CGI script, you will be directed to use either method="get"
method="post"
method="post"
method="get"
Copyright © 2001 Michael Masumoto. All Rights Reserved.