cgi banner gif

home ch01 ch02 ch03 ch04 ch05 ch06 ch07 ch08 ch09 quick reference


Chapter 4: Handling Forms

HTML form basics

Processing the form input


Handling form input is one of the most common uses of CGI scripts today. This is in large part due to the numerous uses for forms. A form is just a group of HTML tags that generate such elements as input fields, list boxes, check boxes, radio buttons, and push buttons. Forms allow the user viewing your Web page to interact with you or your Web site by supplying information or making a selection

In this chapter, you will set up a feedback form that allows the user viewing your pages to send you messages. This will be a simple example of a form and the CGI script needed to handle the input from the form. Because you create forms with HTML and process them with CGI scripts, this chapter briefly reviews the HTML code for creating forms. Again, if you are not already familiar with the HTML of a form or with the concepts of input fields, list boxes, check boxes, radio buttons, and push buttons, you should consult a book on HTML such as HTML3 Manual of Style by Larry Aronson (Ziff-Davis Press, 1995).


HTML form basics

Forms are defined in the HTML specification and not in CGI. CGI simply provides the means for handling the input received from a form. To create a form, you just use the <FORM> tag and the associated <INPUT>, <SELECT>, and <TEXTAREA> tags. A basic form can consist of as little as a single button. However, most forms contain many more elements. This section briefly presents the HTML form tags <FORM>, <INPUT>, <SELECT>, and <TEXTAREA>, and the relevant attributes for the tags.

The <FORM> Tag

All HTML forms begin with the <FORM> tag and end with the </FORM> tag. The <FORM> tag commonly takes two attributes: METHOD and AC