Thursday, May 7, 2009

Creating Web Page Forms

•Creating Web Page Forms
•Designing a Product Registration Form
•Objectives
•Describe how Web forms can interact with a server-based program
•Insert a form into a Web page
•Create and format an input box for simple text data
•Add a form label and link it to a control element
•Objectives
•Set up a selection list for a predefined list of data values
•Create option buttons for a list of possible field values
•Organize fields into field sets
•Insert a text area box for multiple lines of text data
•Objectives
•Generate form buttons to submit or reset a form
•Describe how data is sent from a Web form to a server
•Understand how to create image fields, hidden fields, and file buttons
•Apply tab indices and access keys to control elements
•Introducing Web Forms
•Web forms collect information from customers
•Web forms include different control elements including:
–Input boxes
–Selection lists
–Drop-down lists boxes
–Option buttons or radio buttons
–Check boxes
–Group boxes
–Text areas
–Form buttons
•Forms and Server-Based Programs
•While HTML supports the creation of forms, it does not include tools to process the information
•The information can be processed through a program running on a Web server
•Forms and Server-Based Programs
•Server-based programs are written in many languages
•The earliest and most commonly used are Common Gateway Interface (CGI) scripts that are written in perl
•Other popular languages include:
–AppleScript - PHP
–ASP - TCL
–ColdFusion - the Unix shell
–C/C++ - Visual Basic
•Creating the Form Element
•Creating the Form Element
•Creating the Form Element
•Creating Input Boxes
•The general syntax of input elements is as follows:
Where type specifies the type of input field,
and the name and id attributes provide the
field’s name and id.
•Creating Input Boxes
•Input types:
type=“button”
Displays a button that can be clicked to perform an action from a script
type=“checkbox
Displays a check box
type=“file”
Displays a browse button to locate and select a file
type=“hidden”
Creates a hidden field, not viewable on the form
•Creating Input Boxes
•Input types:
type=“image”
Displays an input image that can be clicked to perform an action from a script
type=“password”
Displays an input box that hides text entered by the use
type=“radio”
Displays an option button
•Creating Input Boxes
•Input types:
type-”reset”
Displays a button that resets the form when clicked
type=“submit”
Displays a button that submits the form when clicked
type=“text”
Displays an input box that displays text entered by the user
•Setting the Size of an Input Box
•By default, an input box displays at 20 characters of text
•To change the width of an input box, use the size attribute which is displayed as follows:
Where value is the size of the input box in characters.
•Setting the Size of an Input Box
•Creating a Password Field
•A password field is an input box where characters typed by the user are displayed as bullets or asterisks to protect private or sensitive information on a Web site
•The syntax for creating a Password field is as follows:

•Creating an input box
•To create an input box, use the following HTML code:
value=“value” size=“value”
maxlength=“value’ />
Where the name and id attributes identify the field, the value
attribute assigns the field’s default value, the size attribute
defines the width of the input box in characters, and the
maxlength attribute specifies the maximum number of
characters that a user can enter into the field.
•Working with Form Labels
•You can also expressly link a label with an associated text element for scripting purposes
•The syntax for creating a form label is as follows:

Where id is the value of the id attribute for a field on the form, and label text is the text of the label.
•Creating a Selection List
•A selection list is a list box from which a user selects a particular value or set of values
–Selection lists are useful when there are a fixed set of possible responses from the user
•You can create a selection list using the
Where value is the number of items that the selection list displays in the form.
•Modifying the Appearance of a Selection List
•Making Multiple Selections
•Add the multiple attribute to the select element to create multiple selections

•Working with Option Groups
•Use option groups to organize selection lists into distinct groups.








•Creating Option buttons
•Option buttons, or radio buttons allow users to make selections.
–Unlike selection lists, option buttons only allow the user to select one option at a time.
•Creating a Field Set
•HTML and XHML allow you to organize option buttons into a group of fields called field sets
–Most browsers place a group box around a field set to indicate that the fields belong to a common group

fields

Where fields are the individual fields within a set.
•Creating a Field Set
•To create a field set, enclose the fields in the following tags:
fields

Where fields are the form fields in the field set. Field sets are
usually displayed in a group box
•Creating a Field Set
•To add a caption to a field set, add the following tag after the opening
tag:
text
Where text is the text of the field set caption.
•Creating Check Boxes
•To create a check box, use:
""
Where the name and id attributes identify the check box field and
the value attribute specifies the value sent to the server if the check
box is selected
•To specify that a check box be selected by default, use the checked attribute as follows:

or

•Creating a Text Area Box
•Text area boxes allow users to enter comments about the products they’ve purchased
•An input box would be too small to accommodate the length of text for this use
•Creating a Text Area Box
•To create a text area box, use the textarea element:

Where the rows and cols attributes define the
dimensions of the input box and the rows attribute
indicates the number of lines in the input box
•Creating a Text Area Box
•Wrap values
•Wrap=“off”
•Wrap=“soft”
•Wrap=“hard”
•Working with Form Buttons
•Buttons are a type of control element that performs an action
•Types of buttons:
–Command button
–Submit button
–Reset button
–File button
•Creating a Command button
•Command buttons are created using the tag:

•Submit buttons submit forms to the server for processing when clicked. Syntax is as follows:

•Reset buttons reset forms to their original (default) values. Syntax is as follows:

•Completed Registration Form
•Designing a Command button
•Use the button element for greater artistic control over the appearance of a button

Where the name and value attributes specify the name of the button
and the value sent to a server-based program, the id attribute
specifies the button’s id, the type attribute specifies the button type,
and the content is page content displayed within the button.
•Creating a File button
•File buttons are used to select files so that their contents can be submitted for processing to a program.
•The Web page then only displays the file’s location, not the file’s contents.
•Working with Hidden Fields
•Hidden fields are added to a form, but not displayed in the Web page. The syntax is as follows:
value=“value” />
•Working with Form Attributes
•After adding the elements to your form, you’ll need to specify where to send the form data and how to send it. Use the following attributes:

Where url specifies the filename and location of the program that processes
the form and the method attribute specifies how your Web browser sends
data to the server. The enctype attribute specifies the format of the data
stored in the form’s field.
•Working with Form Attributes
•The method attribute can have one of two values:
–Post
–Get
•The get method is the default; get appends the form data to the end of the URL specified in the action attribute
•The post method sends form data in a separate data stream, allowing the Web server to receive the data through “standard input”
•Using the mailto Action
•The mailto action accesses the user’s own e-mail program and uses it to mail form information to a specified e-mail address
–By-passes the need for server-based programs
•The syntax is as follows:
mailto:e-mail_address method=“post”
enctype=“text/plain”> …

Where e-mail_address is the e-mail address of the recipient in the form
•Specifying the Tab Order
•Users typically navigate through a form with the tab key
•You can specify an alternate tab order by adding the tabindex attribute to any control element in your form
•The syntax is as follows:

This syntax assigns the tab index number “1” to the fname field from the
registration form
•Specifying an Access Key
•An access key is a single key typed with the Alt key (Windows) or Control key (Mac), in order to jump to one of the control elements in the form
•Create an access key by adding the accesskey attribute to any control element
•Example of creating an access key for the lname field:

No comments:

Post a Comment