creating web page forms. introducing web forms web forms collect information from users web forms...

22
Creating Web Page Forms

Upload: kathryn-blanche-barrett

Post on 04-Jan-2016

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating Web Page Forms

Page 2: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Introducing Web Forms

• Web forms collect information from users • 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

Page 3: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Form on a Web page

New Perspectives on HTML and XHTML, Comprehensive 3

Page 4: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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

Page 5: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating the Form Element

• Forms are created using the form element, structured as follows:<form attributes>

elements</form>

Where attributes are the attributes that control how the form is processed and elements are elements places within the form.

Page 6: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating the Form Element

• Form attributes usually tell the browser the “method” and “actions” to be applied to the form’s data

• Always specify an id or name for the form• Two attributes are available to identify the

form: id and name

Page 7: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating the Form Element

• The syntax of the id and name attributes are as follows:<form name=“name” id=“id”>… </form>

Where name is the name of the form and id is the id of the form.

Page 8: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating Input Boxes

• The general syntax of input elements is as follows:<input type=“type” name=“name” id=“id” />

Where type specifies the type of input field,

and the name and id attributes provide the

field’s name and id.

Page 9: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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

Page 10: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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

Page 11: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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

Page 12: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating Check Boxes

• To create a check box, use:<input type=“checkbox” name=“name” id=“id”value=“value” />

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:

<input type=“checkbox” checked=“checked” />

or<input type=“checkbox” checked />

Page 13: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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

Page 14: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Creating a Command button

• Command buttons are created using the <input> tag:<input type=“button” value=“text” />

• Submit buttons submit forms to the server for processing when clicked. Syntax is as follows:<input type=“submit” value=“text” />

• Reset buttons reset forms to their original (default) values. Syntax is as follows:<input type=“reset” value=“text” />

Page 15: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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:

<form action=“url”method=“type”enctype=“type”>… </form>

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.

Page 16: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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”

Page 17: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –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:<form action-mailto:e-mail_address method=“post”

enctype=“text/plain”> … </form>

Where e-mail_address is the e-mail address of the recipient in the form

Page 18: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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:

<input name=“fname” tabindex=“1” />

This syntax assigns the tab index number “1” to the fname field from the

registration form

Page 19: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

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:

<input name=“lname” accesskey=“1” />

Page 20: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Tips for Creating Effective Forms

• Label all control elements clearly and concisely• Use horizontal lines, tables, and line breaks to separate

topical groups from one another• Use field sets to organize common groups of fields,

especially option buttons• Use the tab order to ensure that users will move correctly

from one field to another

Page 21: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Tips for Creating Effective Forms

• Use option buttons, check boxes, and selection lists whenever possible to limit a user’s choice of entries, thus reducing the chance of an erroneous data value. Use input boxes only when the field has no predefined list of values.

• Use selection lists for items with several possible options. Use option buttons for items with few options. Use a check box for each item with only two possible values.

Page 22: Creating Web Page Forms. Introducing Web Forms Web forms collect information from users Web forms include different control elements including: –Input

Tips for Creating Effective Forms

• Let users know the correct format for input box text by inserting default text in the appropriate format (for example, insert the text string, “mm/dd/yyyy” in a Date input box to indicate the format for inserting date values

• Use password fields for sensitive or confidential information (such as passwords)

• Because form elements differ between browsers, view your form on different browsers and different browser versions to ensure that the form displays correctly in all situations