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:
Text fields and text areas
Radio buttons
Check boxes
Menus of options
Hidden fields
Submit form and reset form buttons
Forms are constructed using a container <FORM>.. </FORM>
Forms may contain the following tags:
<TEXTAREA> - accepts multiple lines of text
<SELECT> - enables selection of one of many alternatives
<INPUT> - used to construct other input widgets, such as:
¨ single lines of text, radio buttons, check boxes, submit or clear
buttons
<FORM> Tags
It is used to define a form
Attributes:
ACTION - It identifies the server program (CGI script) that will
receive and process the form
METHOD - Specifies the method the information within the form
is sent to the script {"POST", "GET"}
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:
NAME - defines the name for the information segment.
This attribute is required.
ROWS - specifies the number of rows for the area.
COLS - specifies the number of columns for the area.
It si used to create a menu selection list or a scrolling list. Attributes:
NAME - specifies the name of the information item. It is a required attribute.
SIZE - specifies the number of alternatives that are shown at one time.
If this attribute is omitted, all alternatives are shown in a drop-down list.
If the value of this attribute is larger than available alternatives, a
NOTHING alternative is added.
MULTIPLE - allows for multiple selections.
OPTION - is used to define an alternative. Attributes for OPTION are:
VALUE - is used to specify the value to be returned (within
the form) if that option is selected.
Input tag is very versatile tag. It is used to create a number of different
form components, e.g.
Input text fields
Password fields
Checkboxes
Radio buttons
Form reset and submit buttons
Input tag is used to specify an input field. This field may of a number of
different types. The type of the field is defined by TYPE attribute.
Input tag attributes are:
NAME - specifies the name of the information item. It is a required
attribute.
TYPE - specifies the type of the input field {TEXT, PASSWORD,
CHECKBOX, RADIO, RESET, SUBMIT}
SIZE - specifies the length in characters (visible portion) for the
field (for text and password types).
MAXLENGTH - specifies the maximum length in characters for the field
(for text and password types).
VALUE - defines the default text value for a text or password type
of input field. For an input field of RESET or SUBMIT type this
attribute is used to define the label on a reset or submit button.
CHECKED - sets the field as checked by default (for RADIO type).
INPUT Text Field
Is used to create a single line input text field.
Example:
<INPUT TYPE="text" NAME="myfield" SIZE="40" MAXSIZE="70">
where
"myfield" will be the name of the component and the text a reader supplies
will be the value for that field
SIZE="40" specifies that the length of the visible text is 40 characters
MAXSIZE="80" specifies that the total number of characters in the field is 80 characters.
Input Password Field
This field is very similar to INPUT text field except that all characters
input by the reader are shown masked with an asterisks or bullet characters.
INPUT Check Boxes
This type of field is used to create multiple selection items. General
format for a checkbox field:
<INPUT TYPE="checkbox" NAME="selection1">Selection 1
Example of a form with checkboxes:
<HTML>
<HEAD><TITLE>Selection Bozes</TITLE></HEAD>
<BODY>
<H1>Selection Boxes</H1>
<FORM>
<MENU>
<LI><INPUT TYPE="checkbox" NAME="Monday">Monday
<LI><INPUT TYPE="checkbox" NAME="Tuesday" CHECKED>Tuesday
<LI><INPUT TYPE="checkbox" NAME="Wednesday">Wednesday
<LI><INPUT TYPE="checkbox" NAME="Thursday" CHECKED>Thursday
<LI><INPUT TYPE="checkbox" NAME="Friday">Friday
<LI><INPUT TYPE="checkbox" NAME="Saturday">Saturday
<LI><INPUT TYPE="checkbox" NAME="Sunday">Sunday
</MENU>
</FORM>
</BODY></HTML>
Its view:
Selection Bozes
Selection Boxes
Radio Buttons
Usually input fields of type radio are grouped together and all have
the same NAME (field name), so only one value under the same name
is returned when one radio button is selected. The format for a
radio button field:
<INPUT TYPE="radio" NAME="dayofweek " VALUE="Monday">Monday
Is used to clear all user supplied information from a form. The
default values (text and password types) remain. The text value
supplied in the VALUE attribute is displayed on the reset button.
<INPUT TYPE="reset" VALUE="Reset The Form">
SUBMIT Type
Is used to send request for the information within the form to be sent
to a CGI server.
<INPUT TYPE="submit" VALUE="Report The Crisis">
Hidden Fields
These fields are not presented with the form, however the values
defined in these fields are passed to a CGI script program. Format:
<INPUT TYPE="hidden" NAME="field" VALUE="valueInTheField">
Information Organization
Convenient structures to organize information in a form:
<PRE> tags
Tables
Lists
Examples of Complete Form
<HTML>
<HEAD>
<TITLE>Forms</TITLE>
</HEAD>
<BODY>
<H1> An Attempt To Forms</H1>
<H2>Form with TextArea and a SelectionBox </H2>
<FORM>
<H3> A TextArea with 5 Rows and 60 Columns and 2 Lines of Default Text</H3>
<TEXTAREA NAME="event" ROWS=5 COLS=60>
Event in October 1997
This is second line
</TEXTAREA>
<P>
<HR WIDTH=50% ALIGN=LEFT>
<P>
<H3>A SelectionBox with 4 Alternatives </H3>
<SELECT NAME="alternatives">
<OPTION VALUE="alternative1">Alternative1
<OPTION VALUE="alternative2">Alternative2
<OPTION VALUE="alternative3">Alternative3
<OPTION VALUE="alternative4">Alternative4
</SELECT>
</FORM>
<HR SIZE=10 COLOR=RED>
<H2>2nd Form with TextArea and a SelectionBox </H2>
<FORM>
<H3> A TextArea with 5 Rows and 60 Columns and 2 Lines of Default Text</H3>
<TEXTAREA NAME="event" ROWS=5 COLS=60>
Event in October 1997
This is second line
</TEXTAREA>
<P>
<HR WIDTH=50% ALIGN=LEFT>
<P>
<H3>A SelectionBox with 4 Alternatives with MULTIPLE Attribute</H3>
<P>
<SELECT MULTIPLE NAME="alternatives" SIZE="4">
<OPTION VALUE="alternative1">Alternative1
<OPTION VALUE="alternative2">Alternative2
<OPTION VALUE="alternative3">Alternative3
<OPTION VALUE="alternative4">Alternative4
</SELECT>
</FORM>
<P>
<HR SIZE=10 COLOR=RED>
<H2>3rd Form with TextArea and a SelectionBox with Size=2 </H2>
<FORM>
<H3> A TextArea with 5 Rows and 60 Columns and 2 Lines of Default Text</H3>
<TEXTAREA NAME="event" ROWS=5 COLS=60>
Event in October 1997
This is second line
</TEXTAREA>
<P>
<HR WIDTH=50% ALIGN=LEFT>
<P>
<H3>A SelectionBox with 4 Alternatives with SIZE = 2 Attribute</H3>
<P>
<HR>
<P>
<SELECT NAME="alternatives" SIZE=2>
<OPTION VALUE="alternative1">Alternative1
<OPTION VALUE="alternative2">Alternative2
<OPTION VALUE="alternative3">Alternative3
<OPTION VALUE="alternative4">Alternative4
</SELECT>
</FORM>
<P>
<HR SIZE=10 COLOR=RED>
<H2>4th Form with TextArea and a SelectionBox with SELECTED Attribute</H2>
<FORM>
<H3> A TextArea with 5 Rows and 60 Columns and 2 Lines of Default Text</H3>
<TEXTAREA NAME="event" ROWS=5 COLS=60>
Event in October 1997
This is second line
</TEXTAREA>
<P>
<HR WIDTH=50% ALIGN=LEFT>
<H3>A SelectionBox with 4 Alternatives with SELECTED Attribute</H3>
<P>
<SELECT MULTIPLE NAME="alternatives">
<OPTION VALUE="alternative1">Alternative1
<OPTION VALUE="alternative2">Alternative2
<OPTION SELECTED VALUE="alternative3">Alternative3
<OPTION VALUE="alternative4">Alternative4
</SELECT>
</FORM>
<H2>5th Form with TextArea and
a number of INPUT fields</H2>
<FORM>
<H3> A TextArea with 5 Rows and 60 Columns and 2 Lines of Default Text</H3>
<TEXTAREA NAME="event" ROWS=5 COLS=60>
Event in October 1997
This is second line
</TEXTAREA>
<P>
<HR WIDTH=50% ALIGN=LEFT>
<P>
<H3>Input Fields</H3>
<P>
... An input text field: <INPUT TYPE="text" NAME="text-field"
SIZE=10 MAXLENGTH=20>
<P>
... An input password field: <INPUT TYPE="password"
NAME="password-field" SIZE=10 MAXLENGTH=10>
<P>
... An input checkbox field: <INPUT TYPE="ckeckbox"
NAME="cleckbox-field" VALUE="value1" CHECKED>
<P>
... Two input radio field: <INPUT TYPE="radio"
NAME="radio-field" VALUE="value2" CHECKED>Really
<INPUT TYPE="radio"
NAME="radio-field" VALUE="value6">Not Really
<P>
<INPUT TYPE="RESET" VALUE="Clear the Form">
<P>
<INPUT TYPE="SUBMIT" VALUE="Send the Information?!?">
</FORM>
</BODY>
</HTML>
Its View:
Forms
An Attempt To Forms
Form with TextArea and a SelectionBox
2nd Form with TextArea and a SelectionBox
3rd Form with TextArea and a SelectionBox with Size=2
4th Form with TextArea and a SelectionBox with SELECTED Attribute
5th Form with TextArea and
a number of INPUT fields
Example: Another Form
<HTML>
<HEAD>
<TITLE>Forms</TITLE>
</HEAD>
<BODY>
<CENTER>
<H1> Structured Forms</H1>
</CENTER>
<P>
<HR SIZE=10>
<P>
<H2>1 - Form Using PRE Tag </H2>
<FORM>
<PRE>
University: <INPUT TYPE="text" NAME="school" SIZE="40" VALUE="SDSU">
Course: <INPUT TYPE="text" NAME="subject" SIZE="20" VALUE="Multimedia">
Degree: <INPUT TYPE="text" NAME="diploma" SIZE="30">
<P>
<INPUT TYPE="RESET" VALUE="Clear the Form">
<P>
<INPUT TYPE="SUBMIT" VALUE="Send the Information?!?">
</PRE>
</FORM>
<P>
<HR SIZE=10>
<P>
<H2>2 - Form Using a Table Structure </H2>
<FORM>
<TABLE BORDER=10 CELLSPACING=10 BGCOLOR="Gray" BORDERCOLOR="BLACK">
<CAPTION>Software Projects</CAPTION>
<TR>
<TH WIDTH=20% HEIGHT=80>Project Name</TH><TH WIDTH=15%>Manager</TH><TH WIDTH=15%>Completetion Date</TH>
</TR>
<TR>
<TD HEIGHT=40><INPUT TYPE="text" NAME="project1" SIZE="40"></TD>
<TD><INPUT TYPE="text" NAME="manager1" SIZE="30">
<TD><INPUT TYPE="text" NAME="date1" SIZE="30"> </TR>
<TR>
<TD HEIGHT=40><INPUT TYPE="text" NAME="project2" SIZE="40"></TD>
<TD><INPUT TYPE="text" NAME="manager2" SIZE="30">
<TD><INPUT TYPE="text" NAME="date2" SIZE="30"> </TR>
<TR>
<TD HEIGHT=40><INPUT TYPE="text" NAME="project3" SIZE="40"></TD>
<TD><INPUT TYPE="text" NAME="manager3" SIZE="30">
<TD><INPUT TYPE="text" NAME="date3" SIZE="30"> </TR>
<TR>
<TD><INPUT TYPE="RESET" VALUE="Clear the Form"></TD>
<TD><INPUT TYPE="SUBMIT" VALUE="Send the Information?!?"> </TD>
</TR>
</TABLE>
</FORM>
<P>
<HR SIZE=10>
<P>
<H2>3 - Form Using List Structure </H2>
<FORM>
<H4> List Courses You Would Like to Study </H4>
<OL>
<LI><INPUT TYPE="text" NAME="course1" SIZE="15">
<LI><INPUT TYPE="text" NAME="course1" SIZE="15">
<LI><INPUT TYPE="text" NAME="course1" SIZE="15">
<LI><INPUT TYPE="text" NAME="course1" SIZE="15">
</OL>
<P>
<INPUT TYPE="RESET" VALUE="Clear the Form">
<P>
<INPUT TYPE="SUBMIT" VALUE="Send the Information?!?">
</FORM></BODY></HTML>