While most other HTML elements are used to present information on your page, an HTML form is used to gather information from your users. Most modern web sites, will interact with their users through forms. For example, you will need to have
a form to allow users to place orders, send you a message, or to track their orders.
How does a form work?
The form itself, does not process the input. It only gathers input from the user and sends the information back to the web server. To process information from a form, you will need to use server side programming
such as CGI, Perl, ASP, PHP. For ASP.NET, HTML forms can be used, but there
are better options to interact with users (ASP.NET topics are covered in their
own series of tutorials). The following interactive process takes place when a user access a page that contains a form.
- The visitor fills in the form and submits
- The browser sends the submitted form data to the web server
- A form processor is running on the web server processes the form data
- A response page is sent back in HTML to the browser
A form can contain input elements of type such as text boxes, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. A starting and ending <form> tag is used to
create a form.
... input elements ...
There are several attributes that you can assign to the form element. However, the only required attribute is "action". The "action" attribute points to the server side script that handles the form submission. Another optional attribute that is commonly used is "method".
You assign the "method" attribute to either GET or POST. If you use GET method, the form submission values are passed as part of the URL (QueryString).
If it is POST, the information is sent to the server as part of the data body and will not be visible in the URL box in the user’s browser. If you don’t specify the method, GET is used by default. Here is an example.
<form action="cgi-bin/form.pl" method="post">|
... input elements ...
Now that you have your form, you need to add input elements. As discussed earlier, input elements include text boxes, checkboxes, radio, and buttons.
The <input /> element is used to gather information. An input element can vary in many ways, depending on the type attribute. An input element can be of type text, checkbox, password, radio, reset, and submit. Here are some examples.
A submit button is used to send form data to the web server. The data is sent to the page specified in the form's action attribute. The action page will run the code against the data and return the results back to the user.
Recommended Books & Training Resources