Intermediate HTML


© Irene Herz

Lesson 4: Using forms to get visitor feedback

Every time you use a search engine, order something online, or register for a newsletter you are filling in an HTML form.

A form is part of an HTML page. Within it are fill-in-the-blank text boxes, check boxes, drop down lists and those little round things called radio buttons. Visitors to your site enter their information, then click a Submit button to send what they've filled in to the webmaster requesting the information.

Forms are incredibly useful. So much so that the most common ones, like guestbooks and "recommend this site to a friend" forms are available as remotely hosted programs, free for you to use. (See Lesson 3: CGI/PERL.)

In this lesson you'll learn how to create a form and how to mine those script libraries from the last lesson to find a script that will send the results to you, the webmaster.

The form of a form

First of all, every form must be enclosed in <form> tags. Yes, you guessed it. They look like this:

<form>
...
...
</form>

Actually, there's a little bit more that goes into the beginning form tag. You have to tell the server two things:

  1. the name of the program that you want to be executed when the user clicks the "Submit" button
  2. whether the form's type is query or post. So the full form tag looks like this:
<form method="post" action="someprogram.cgi">
...
...
</form>

The "get" type of form, as opposed to the "post" type, sends everything the user enters as part of the URL. You know how sometimes you see a long URL that looks something like

blahblah.com⁄AIDLink.php?BID=2279&AID=16105

Well, the stuff after the question mark is a bunch of parameters. Parameters are simply values that are passed from one page to another. For example, if a form had a question about your age, you might see a URL like

http:⁄⁄www.processthis.cgi?age=32

So when you specify a form type of "get", everything the user types in, and any hidden values you've added, will be right up front, in the address of the destination page. One drawback of using "get" is that the length of the query string, meaning the URL with those parameters on the end, is limited to as little as a few hundred characters. (The length varies from browser to browser.)

The "post" type of form passes on its data differently. (I won't bore you with the details.) So the visitor's responses are not part of the URL. I'd say most forms are of this type.

We won't bother with specifying a form type till later. For the purposes of building and testing our form, it's enough to use the <form>...</form> tags without specifying a form type or destination.

Now we move on to the components that make up a form.



1  2  3  4  5   Next Page

Print this Page Print this page