Tutorial 6: Creating Web Page Forms
Tutorial 6: Creating Web Page Forms
XP
An Example of a Form
XP
XP
XP
XP
group box
Network Operating System (check all that apply) Netware Banyan Vines Windows IBM Lan Server PC/NFS
radio buttons
Comments?:
form button
Send Registration
Cancel
XP
XP
A single Web page can contain multiple forms, the <form> tag includes the name attribute. The name attribute identifies each form on the page. The name attribute is also needed for programs that retrieve values from the form.
XP
XP
contact information
product information
usage information
comments
buttons
XP
Input Types
Type type=button type=checkbox type=file type=hidden type=image type=password type=radio type=reset type=submit type=text Description Display a button which can be clicked to perform an action from a script Display a check box Display a browse button to locate and select a file Create a hidden field, not viewable on the form Display an inline image which can be clicked to perform an action from a script Display a text box in which hides text entered by the user Display a radio (option) button Display a button which resets the form when clicked Display a button which submits the form when clicked Display a text box in which displays text entered by the user
XP
XP
Name/Value Pairs sent from the Web Form to the CGI Script
This figure shows when form data is sent to the CGI script, the script receives the name or id of each field in the form paired with whatever value the user entered in the field. The script then processes the data according to each name/value pair.
XP
XP
XP
XP
This figure shows an example of limiting the width of the zip code field to five characters.
XP
XP
default value
XP
XP
Using a password field should not be confused with having a secure connection. The password itself is not encrypted. The password field only acts as a mask for a field entry as it is entered.
XP
XP
XP
XP
XP
XP
size = "1"
size = "4"
size = "7"
size = "9"
XP
XP
XP
Option Groups
Internet Explorer and Netscape versions prior to 6.0 display the selection list without the group labels.
option group label a single option group option group label
XP
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.
XP
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.
XP
XP
XP
XP
XP
XP
XP
XP
XP
XP
XP
By themselves, push buttons perform no actions in the Web page. To create an action, write a script or program that runs automatically when the button is clicked.
XP
XP
XP
3. The filename and location are automatically placed in the text box
XP
Place all hidden fields in one location to make it easier to read and interpret the HTML code. Include a comment describing the purpose of the field.
XP
XP
URL - the filename and location of the CGI script that process the form Method - how your Web browser sends data to the CGI script enctype - the format of the data stored in the forms field
XP
The post method sends form data in a separate data stream, allowing the Web server to receive the data through standard input.
the post method is considered the preferred way of sending data to a Web server
XP
This figure shows the CGI script that processes the form is located at the URL http://www.langear.com/cgi/mailer (a fictional address) and uses the post method.
XP
Form Values
The Web browser presents a page, an example of which is shown in this figure, displaying the name of each field in the form and the value assigned to it. At the same time, the CGI script formats a mail message to be sent to the address you entered.
XP
Use the mailto action to send form information via email without using a CGI script. This action accesses the users own e-mail program and uses it to mail form information to a specified e-mail address, bypassing the need for using CGI scripts on a Web server. The syntax of the mailto action is:
<form action=mailto:e-mail_address method=post enctype=text/plain>
XP
Another concern is that messages sent via the mailto action are not encrypted for privacy. The recipients email address is revealed to the user.
XP
XP
Add the tabindex attribute to any control element in the form to specify the tab order. With each element assigned a tab index number, the cursor moves through the fields from the lowest index number to the highest.
for example, to assign the tab index number 1 to the fname field, enter the code: <input name=fname tabindex=1>
XP
XP
7 rows
XP
<form> tag needed after <body> Three <Fieldset> with <legend> for group box