Perl Programming For Librarians: A Beginner's Manual, by Michael R. Leach |
You define a form with the form tag:
<FORM method="Post or Get" action="URL or path"> ... </FORM>
Note: never nest forms! (That is, put one form within another)
You must choose a method attribute; the best one is Post, because it sends form information seperately from the URL. Get, the default, tacks the form information onto the end of the URL. (Some severs only accept a URL of a certain length, so some Get form information could be lost.)
The action attribute points to a script that will do something with the form information. These scripts are located on the Web Server (not on the client/browser), and are written in a computer language (like Basic, C, Perl, etc.), not in HTML. We will discuss scripts in detail later. The path is usually of the form:
"/cgi-bin/comment.script"
There is also an enctype attribute, which specifies the MIME/TYPE used to encode the formıs contents. It can only be used with the Post method, and it has a default "content-type" of "application/x-www-form-urlencoded". The value "multipart/form-data" should be used when the returned document includes submitted files. (See #3, Input Types, below.)
Within the <form ...>...</form> tags are three possible "form field" input tags:
1.)
<TEXTAREA attributes> default text </TEXTAREA>The attributes are:
Name="comments" This attribute is required. The name must be unique, and is case sensitive. The "name" attribute is used to identify a field's content when it is submitted to the server.
Rows=# This is simply the number of rows to be displayed. Required.
Cols=# This is simply the number of columns (width of field) to be displayed. Required.
The default text is any text you want to display within the TEXTAREA box. Most people leave the default text empty. (Note: you never place <html> tags within the default text area.)
2.)
<SELECT attributes><OPTION attribute> text ... (other options)
</SELECT>
I like to think of the <SELECT> tags as the form equivalent of the list tags, with the <SELECT> corresponding to <ul> or <ol>, and the <OPTION> tag corresponding to <li>.
There are three attributes for the <SELECT> tag:
Name="comment" This is just like in the <TEXTAREA> tag
Size=# This attribute determines how many <OPTION> choices are shown. Setting it to 1, and you get a pop-up menu. Setting it to 2 or higher, and you get a scrollable box. Omitting the Size attribute is the same as setting it to 1.
Multiple This attribute allows more than one selection to be made. (Usually, one designs a form so that the user must select one option from a list.) Using Multiple causes a scrollable box to appear.
Each choice, or <OPTION> within the <SELECT> tag has two possible attributes:
Value="unique name" The value "unique name" is what is sent back to the script for processing. It does not have to be the same as the text that appears after the <OPTION> tag.
Selected Value="unique name" The default value (if you wish a default).
Example: <SELECT NAME="flavor">
<OPTION VALUE=a>Vanilla
<OPTION VALUE=b>Strawberry
<OPTION VALUE=c>Rum and Raisin
<OPTION VALUE=d>Peach and Orange
</SELECT>
Note that we could still look at our form even though no script was available, we had no server, and we had no way of sending off the form information. You probably noted as well that there was no way to "send" off the comments, nor any way to "clear" the form if you made a mistake or changed your mind. We will now learn how to do that, and much more, as we look at the third form tag.
3.)
<INPUT attributes> (no closing tag)This tag can be very confusing because it does so many things, yet appears so small. There are six attributes:
Name="comment" Required for all types except submit and reset. Otherwise, similar to the other two input fields.
Type="input type" There are currently six types of "input types":
"text" (the default input type) a simple, single line of text
"password" a modified text input type that is displayed as bullets/asterisks
"checkbox" obvious
"radio" a complicated "checkbox" where only one of a set of radio buttons can be chosen (i.e. a single value from a set of alternatives). Radio buttons of the same set must use the same Name attribute (see the example later).
"reset" a push button that clears the input values of a form.
"submit" a push button that sends the form values to the script
"image" used for graphical submit buttons. The x and y values of the location clicked on the image are passed to the server as two name/value pairs, derived by taking the name of the field and appending ".x" for the x value, and ".y" for the y value.
"file" used to attach a file to the formıs contents. You get a text field and an associated button which when clicked invokes a browser to have you select a file name. The file name can also be entered directly in the text part of the field.
"hidden" not visible/rendered to user. A server can store state information with the form, much like Cookies in http.
Size="#" The number of characters for the "text" and "password" input types that are to be displayed on the form.
Maxlength="#" The maximum number of characters for "text"/"password" that a user can enter (regardless of the size of the Input).
Value="some text" Means different things for different "input types":
for "text/password" defines default text displayed
for "checkbox/radio" specifies value to be returned to server script if selected
for "reset/submit" defines the text displayed within the push button
Checked To set a "checkbox/radio" on. (It has no meaning for other types.)
SRC="url" For fields with background images; also for the Image type.
Align="top | middle | bottom | right | left" (Choose one.) For aligning the input field.
| Last Updated: 6 June 2000 | Table of Contents |
Chapter One |