Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Processing form data

Forms collect information; they don’t do anything with it. A lovely script does all the clever stuff and I can't tell you how to write those but I'll tell you what I do know.

To let a script process the information on a form, you need to add two attributes to the <form> tag. These are method and action.

For example:

<form method="post" action="script.cgi">

The action attribute is the address of the script that processes the information on the form. The method attribute describes how the browser sends the data to the server:

  • If you post the data, the browser contacts the server twice: once to contact the script and then to send the data. You use this method for things like feedback forms which might have a lot of data and you also use it for file transfers
  • If you get the data, the browser puts the form data on the end of the URL when it contacts the server. The server sorts the data out and passes it to the script

If you want to know anymore, you are on your own.

The information is passed to the program in name-value pairs. The value is the information that the user enters and the name is the label that identifies the input.

For example, your form has two inputs labelled name and email:

<form>
Enter your name and email address:
<input type="text" name="name" size=30>
<input type="text" name="email" size=60>
</form>

The user types Ann Gilliver for name and a.gilliver@lineone.net for email. The form passes the information to the program. The labels corresponds to the variable names in the program and the information that the user enters is the value for the variable. This means that each input must have a unique name attribute.

The program can do what it likes with the information but it will probably e-mail the user with further information.