formHTMLThe three parts of an HTML  form are:

  1. FORM tag (Method and Action)
  2. Form elements (How to Write HTML Forms, Part I)
  3. Submit button (Sends the data to the CGI script)

This post will cover the ACTION and METHOD parts of the FORM tag.

ACTION – this defines where on the server the CGI script is located. If you remember from our Introduction to CGI, the script is a small program stored in the CGI-bin of the root directory. Without a script, the form will not work.

METHOD (there are two choices):

GET – this method uses a link to contain specific ‘pre-input’ data so that the data is sent to the server and processed by the script then when the visitor clicks on the link the browser displays the result. Example: You may have a page that asks the question ‘ What is the temperature?” with a list of links underneath the question for cities in your state. When the visitor clicks on the city they want the temperature for, the data is sent to the script for processing and the browser displays the temperature in that city.

POST – this method collects the data and sends it back to you for use at a later time. For this post we will be assume you want to have the data sent back to you in email form.

Sample HTML code for ‘Method’ and ‘Action’ :

identifies the beginning of the form

ACTION=”/cgi-bin/”identifies the location and name of the script  that is to perform the action, i.e., the cgi-bin,, respectively.   (Note: In this case the cgi-bin location is preceded by a forward slash – using this slash defaults the location to the root directory, ie.,

METHOD=”POST” identifies the method of action as ‘post’ which will send the collected data to you as an email.

The remainder of the FORM tag will contain the information that defines the input fields, the subject line of the email, the redirect to the ‘thank you page’, and the fields that are required. See HTML Forms, Part III – INPUT (Coming next)

You can find more information on writing HTML forms in one of the HTML Quickstart Guides by Elizabeth Castro . . . and, if you want to learn how to write your own scripts The Quickstart Guide by Elizabeth Castro for Perl and CGI is an excellent reference.

Comments are closed.