HTML forms are the primary way in which online commerce occurs. Without forms for customer input (mailing address, credit card information, etc.), there will not be such a bustling online industry. The HTML form is the interface in which readers enter data, but this is only the input. The data needs to be processed on the web server using applications or in the Common Gateway Interface (CGI). The CGI is the “communication bridge” between the web server and the internet. The CGI collects data sent by the user through HTTP (Hypertext Transfer Protocol, the web browser, basically), using computer programs called scripts. It then transfers the data to a variety of data-processing programs that are running on the server. It can work on the data and then send back confirmation (or any other type of information) to the CGI that in turns sends it to the original sender.
<form> is the container element that will create forms in HTML. This element has the following attributes: action, enctype, method, accept, and accept-charset. The two attributes to remember are:
- action: the URL of the application that processes the form data; this URL points to a script file or an email address
- method: specifies the HTTP method used to submit the form data; the default value is “get”
- get – the form data is appended to the URL specified in the action attribute
- post – the form data is sent to the server as a separate message
Creating Input Objects
The <input> element defines many of the form input object types. You use the type attribute to specify the object type. Type attributes include: text, password, checkbox, radio, submit, reset, hidden, image, button, and file. “Text” is the default object type.
The <label> element allows you to put a caption to the input object. For example, you have a text input object. You might want to describe what you are expecting your readers to type in, so you can say “First name” to the left of the input box and people will know to type in their first names. The code may look like this:
<label class=”username”>First Name:</label>
<input type=”text” name=”firstname”
There is so much more detail to creating a form than I really want to take notes on. I’ll frequent my textbook the next time I need to create a form…