tag is used to define a form and attributes specify how form data is processed and sent to CGI scripts. A variety of input types are supported in HTML forms, including text, password, checkbox, radio button, submit button, and file upload."> tag is used to define a form and attributes specify how form data is processed and sent to CGI scripts. A variety of input types are supported in HTML forms, including text, password, checkbox, radio button, submit button, and file upload.">
Form and CGI
Form and CGI
1
XP
Objectives
3
The Interaction between a XP
Web Page Form and a CGI Script
4
XP
Working with CGI Scripts
5
XP
6
XP
CGI Script Restrictions
There are several reasons to restrict direct
access to CGI scripts:
CGI scripts are actually running a program
directly on the server
security risks from computer hackers
drain on system resources caused by large
numbers of programs running simultaneously
System administration are understandably
careful to maintain strict control over their
servers and systems.
7
CGI Scripts and Computer XP
Languages
CGI scripts can be written in a variety of different computer
languages. Some of the most commonly used languages
are:
AppleScript
ASP
C/C++
Perl
TCL
The UNIX shell
Visual Basic
Other server side scripts PHP,ASP,ASP.NET
The computer language used depends on the Web server.
8
Form Components and XP
Elements
text box
First Name Last Name
This figure shows Address #1
form Send
SendRegistration
Registration Cancel
Cancel
button
9
XP
Form Control Elements
11
XP
The <form> Tag
14
XP
Structuring a Form
Horizontal lines can provide structure
to a form by separating sections.
15
XP
Input Types
This figure Type Description
shows other type=”button” Display a button which can be clicked to
perform an action from a script
supported
type=”checkbox” Display a check box
HTML input
types. type=”file” Display a browse button to locate and select a
file
type=”hidden” Create a hidden field, not viewable on the form
type=”image” Display an inline image which can be clicked to
perform an action from a script
type=”password” Display a text box in which hides text entered
by the user
type=”radio” Display a radio (option) button
type=”reset” Display a button which resets the form when
clicked
type=”submit” Display a button which submits the form when
clicked
type=”text” Display a text box in which displays text
entered by the user
16
XP
Working with Text Boxes
box
size attribute defines the width of the text box in
number of characters
maxlength attribute defines the maximum number
20
XP
CGI Script Names
21
XP
Text Boxes on the Form
22
Controlling the Size of a XP
Text Box
characters
23
Setting the Width of XP
Text Boxes
This figure
shows an
example of code
for setting the
width of text
boxes.
24
Result of Setting the XP
Netscape users
may have to
close and open
the file for the
changes to the
Web form to
take effect.
25
Setting the Maximum LengthXP
for Text Input
Setting the width of a text box does not limit the
number of characters the box can hold.
if a user enters text longer than the box’s width, the
text scrolls to the left
the user cannot see the entire text, but all of it is
sent to the CGI script for processing
The syntax for setting the maximum length for field
input is:
<input maxlength=“value”>
value is the maximum number of characters that
can be stored in the field
26
Specify the Maximum Length XP
for a Field
This figure shows an example of limiting the width of the zip code field to five characters.
no more than 5
characters are
allowed in this text
box
27
Setting a Default Value for aXP
Field
When the same value is entered into a field,
it may make sense to define a default value
for a field.
Default values can save time and increase
accuracy for users of a Web site.
To define a default value, use the following
syntax:
<input value=“value”>
value is the default text or number that is
displayed in the field
28
Defining a Default Value for a XP
Field
If customers from countries other than the United States use this Web form,
they can remove the default value by selecting the text and pressing the Delete key.
default value
29
XP
Creating a Password Field
form
label text is the text of the label
31
Creating a Label for the XP
fname Field
This figure shows
a label for the
fname field.
value of the id
attribute for the first
name field
32
XP
Creating a Selection List
33
Using the <select> XP
35
XP
Using a Selection List
Your selection
list might look
slightly different
depending on the
browser and
browser version.
36
Modifying the Appearance XP
of a Selection List
HTML provides several attributes to modify the
appearance and behavior of selection lists and
options.
By default, the <select> tag displays one option
from the selection list, along with a list arrow to view
additional selection options.
The number of options displayed can be modified
with the size attribute.
The syntax of the size attribute is:
<select size=“value”>
37
Modifying the Appearance XP
38
Selection Lists with XP
Different Size Values
This figure shows
selection lists with
different size
values. size = "1" size = "4"
40
Making Multiple Selections XP
Continued
The Windows operating system, multiple
selections can be made as follows:
for noncontiguous selections, press and hold
the Ctrl key while you make your selections
for a contiguous selection, select the first
item, press and hold the Shift key, and then
select the last item in the range
Check and verify that the CGI scripts used are
designed to handle multiple selection lists.
41
XP
Working with Option Values
43
XP
Option Groups
option
a single group label
option
group a single option
group
44
XP
Working with Radio Buttons
Radio buttons display a list of choices from which a
user makes a selection.
Only one radio button can be selected at a time.
The syntax to create a radio button is:
<input type=“radio” name=“name” id=“id”
value=“value”>
name identifies the field containing the radio button
id attribute identifies the specific option. Only required
if you intend to use a field label with the radio button
value attribute indicates the value sent to the CGI
script, if that radio button is selected by the user
45
XP
Creating Radio Buttons
This figure shows an example of HTML code that creates radio buttons for party affiliations.
In this sample code, the value sent to the CGI script does not match the field label.
If the user selects the Republican radio button, the value “gop”
is sent to the CGI script paired with the field name “party.”
46
Selection Lists vs. Radio XP
Buttons
48
Creating a Group Box XP
Continued
49
Creating a Group Box and XP
Legend
start of group box
This figure shows group box legend
an example of a
group box applied
to a set of radio
buttons.
50
XP
Group Box Size
There is no attribute to control the size of a group
box.
The box’s height will be large enough to
accommodate the fields and labels in the field set.
The width is the width of whatever space remains
on the Web page.
To set the width to a specific value use a table cell
to place the group box and set the width of the cell.
group boxes cannot extend across table cells; all of
the fields in the field set must be placed within a
single cell
51
XP
Working with Check Boxes
A check box is either selected or not, there is only one
check box per field.
Check boxes are created using the following syntax:
<input type=“checkbox” name=“name” id=“id”
value=“value”>
name and id attribute identify the check box
the value attribute specifies the value that is sent to the
CGI script when the check box is selected
The <input> tag for a check box does not display any
text.
Check boxes are not selected by default.
to do this, add the checked attribute to the <input> tag
52
XP
53
Group Boxes for Radio Buttons XP
and Check Boxes
54
XP
Creating a Text Area
56
XP
Wrap Attribute Values
The text entered in a text area wraps to the next line when it exceeds the width of the
box. To control how a browser wraps text to a new line use the wrap attribute.
This figure shows the three possible wrap options.
57
XP
The wrap Attribute for Text
59
XP
Creating Form Buttons
60
XP
Creating a Push Button
One type of button, called a push button, is
created using the <input> tag as follows:
<input type=“button” value=“text”>
text is the text that appears on the button
61
Creating Submit and Reset XP
Buttons
A submit button is a button that submits
the form to the CGI script for processing.
A reset button resets the form to its original
(default) values.
The syntax for creating these two buttons is:
<input type=“submit” value=“text”>
<input type=“reset” value=“text”>
value attribute defines the text that appears on
the button
62
The name and value XP
Attributes
The name and value attributes can be used
for push, submit, and reset buttons.
Use these attributes when the form contains
multiple buttons and a program that
processes the form needs to distinguish one
button from another.
for example, a Web page advertising a shareware
program might include three buttons:
one used to download the program
another used to retrieve information
the third to cancel the form
63
XP
Creating a Form Button
The figure shows HTML tags for buttons that download a program,
retrieves information, and resets the form to its original values.
64
Creating Buttons XP
with the <button> Tag
Buttons created with the <input> tag do not allow the Web
page designer to control the appearance of the button.
For greater artistic control over the appearance of the
button, use the <button> tag.
The syntax of the <button> tag is:
<button name=“name” value=“value”
type=“option”>
button text and HTML tags
</button>
name attribute specifies the name of the button
value attribute sends to a CGI script
type attribute specifies the button type (submit, reset, or
button)
65
XP
Using the <button> Tag
66
XP
Creating File Buttons
67
XP
Using a File Button
Inline images can act like submit buttons, so that when the user
clicks the image, the form is submitted.
The syntax for this type of control element is:
<input type=“image” src=“URL” name=“text”
value=“text”>
URL is the filename and location of the inline image
name attribute assigns a name to the field
value attribute assigns a value to the image
When the form is submitted to the CGI script, the coordinates of
where the user clicked are attached to the image’s name and value
in the format: namex_coordinate, value.y_coordinate.
69
Using an Image Control XP
with a CGI Script
70
XP
Working with Form Attributes
74
Form Values XP
75
XP
Using the “mailto” Action
The format of
the mail
message may
look different
depending on
the browser or
e-mail software.
77