Perl Lesson 4: Forms
Home Lesson 4: Forms

Home
FAQ
Uses of Perl
Perl Lessons
The Experience
Testing Area
Perl Links
Guestbook
About the Site

To get information from someone looking at a homepage to a program on the server, there has to be some way to enter the information. The thing that does this is called forms.

Forms are a set of fields, places where information can be entered, that after submission, the information is sent to the server and a program processes it.

In this lesson, we will concentrate on the forms and how to make them.

First, here is a sample form, in which you would enter your name, and then submit it.




Now the explanation:

<form></form> : The form tag tells the browser that the enclosed text is a form. You must make sure that you close the form for it to work completely.

<...action="cgi-bin/name.cgi"> : The action attribute tells the browser what program will process the information when submitted.

<...method="post"> : The method attribute tells the browser how to send the information. There are two methods, get and post. This is not really important now, but you will learn more about this later.

<input...> : This tag tells the browser to display an input field so that you can enter text.

<...type="..."> : The type of input field is important, because each one does a different job. The text type lets you enter in text, but only into a one line box. The submit type is a button which you press to send the information to the server and the program named in the action.

Here are the properties for the most important <input...> :

Input Property Description
text name the name of the field, used by scripts
value text that is displayed next to the checkbox
checkbox if 'checked' is present, then the checkbox is checked by default
radio name value (same as checkbox)
checked same as checkbox except only one radio button may be checked by default

Here are the most important properties for the <...type="..."> inputs:

Type Input Description
text Displays a one line box that can enter text.
checkbox Displays a square "check" box, which can be checked and unchecked. As many checkboxes as you want can be checked within a list of boxes in a form.
radio Displays a round "radio" button, which only one can be selected within a list of the radio buttons in a list in a form.
submit Displays a button which submits the information.
reset Displays another button which resets the form to the default properties, usually clearing the form.

To use these properties, insert (for example) the name "hello" into the <input> tag.

Chapter 3: Program Control-so who's really in charge? Home Chapter 5: Reading input from forms-a 'form'idable challenge

<<< Chapter 3 | Home | Chapter 5 >>>