CS 561 - Lecture Notes
Forms






Forms are used to collect information from a reader. They are most powerful tool to interact with a reader. The information supplied by the reader is sent to a program residing on a server. This program is usually referred to as a CGI script.

A form includes the following components:

<FORM> Tags

Using the POST method the browser sends the reader information separately from the URL of the CGI script.
Using the GET method the browser appends the reader's information appended to the script URL.
Example of a FORM tag:
<FORM METHOD="GET" ACTION="www.multimedia.sdsu.edu/cgi-bin/calendar">
NOTE: Forms cannot be nested.

Form Mechanism

When a form is filled by a reader and submitted a CGI program is invoked on the server side, in the example above it would be the program calendar with the following URL:
www.multimedia.sdsu.edu/cgi-bin/calendar
The data provided by the reader would be attached to the URL. The CGI program can extract the data and use it to create an HTML document. That document is sent back to the client and presented to the reader.
For example the following HTML document
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY BGCOLOR="AQUA" TEXT="BLACK" LINK="GREEN" VLINK="BLUE" ALINK="RED">
<H1>Get Currentt Date</H1>
<A HREF="http://www.multimedia.sdsu.edu/cgi-bin/returndate">Display the Date</A>
</BODY>
</HTML>
will invoke the CGI program "returndate" with URL:
http://www.multimedia.sdsu.edu/cgi-bin/returndate
The program is written in Unix C shell, and it returns the current date and time.
#!/bin/sh
echo Content-type: text/html
echo
cat << EOF
<HTML><HEAD>
<TITLE>Date</TITLE>
</HEAD>
<BODY>
<P>The current date is: <B>
EOF
/bin/date
cat << EOF
</B></BODY></HTML>
<EOF>

Other Form Related Tags

We will now discuss tags used to construct components within forms. We will note one thing in common with all components: name and value:
For every input components the form author has defined the property "name". Together with the name there is property "value". The actual value for the property "value" is supplied by the browser at the time the form is submitted. In other words for every component within the form the browser creates a property pair NAME="name" VALUE="value". This enables a CGI script program to determine the value for each name, e.g. name=value.

<TEXTAREA> Tag

It provides an area for input of a number of lines of text. By default the visual aperture is 4 lines of 40 characters. Default text can be enclosed between < TEXTAREA> and </TEXTAREA>.
Attributes: Netscape extension attribute WRAP:
WRAP={OFF, SOFT, HARD}

<SELECT> Tag

It si used to create a menu selection list or a scrolling list. Attributes: