home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Platinum Edition Using HTML 4, XML, and Java 1.2
(Publisher: Macmillan Computer Publishing)
Author(s): Eric Ladd
ISBN: 078971759x
Publication Date: 11/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


CHAPTER 8
Forms

by Eric Ladd

In this chapter
Overview: Forms and CGI 234
Creating Forms 234
Labeling Input Fields 250
Grouping Related Fields 251
Disabled and Read-Only Fields 253
Form Field Event Handlers 254
Passing Form Data 254
Creating Forms with Authoring Tools 256

Overview: Forms and CGI

As the Web becomes more interactive, the need for interface components to gather data from users is greater than ever. Fortunately, this need was anticipated in earlier versions of HTML and resulted in the introduction of the form tags. Forms are the visible or front-end portion of interactive pages. Users enter information into form fields or controls—user interface elements that are similar to those found on Windows and Macintosh operating systems—and click a button to submit the data. The browser then packages the data, opens an HTTP connection, and sends the data to a server. Things then move to the transparent or back-end part of the process.

Web servers are programs that know how to distribute Web pages. They are not programmed to process data from every possible form, so the best they can do is hand off the form data to a program that does know what to do with it. This handoff occurs with the help of the Common Gateway Interface or CGI—a set of standards by which servers communicate with external programs.

The program that processes the form data is called a CGI script or a CGI program. The script or program performs manipulations of the data and composes a response—typically an HTML page. The response page is handed back to the server (via CGI), which in turn passes it along to the browser that initiated the request.

• To learn more about CGI programming, see “Programming CGI Scripts,” p. 689.

Forms and CGI are opposite sides of the same coin. Both are essential to creating interactive pages, but it is the forms side of the coin that the user sees. This chapter examines how to create Web forms and gives an overview of some of the behind-the-scenes activity that has to occur to produce the custom pages, electronic commerce sites, and other dynamic functionality that Web users have come to love.


NOTE:  When a CGI script or program composes an HTML page, it is said to be generating HTML on-the-fly. The capability to generate pages on-the-fly is what makes custom responses to database and forms submission possible.

Creating Forms

HTML’s form support is simple and complete. A handful of HTML tags create the most popular elements of modern graphical interfaces, including text windows, check boxes and radio buttons, pull-down menus, and push buttons.

Composing HTML forms might sound like a complex task, but you need to master surprisingly few tags to do it. All form-related tags occur between the <FORM> and </FORM> container tags. If you have more than one form in an HTML document, the closing </FORM> tag is essential for distinguishing between the multiple forms.


Adding a </FORM> tag immediately after creating a <FORM> tag is a good practice; then you can go back to fill in the contents. Following this procedure helps you avoid leaving off the closing tag after you finish. Many of today’s popular HTML editing programs take care of placing the </FORM> tag for you, so be sure to check to see if the editor you’re using does this.

Each HTML form has three main components: the form header, one or more named input fields, and one or more action buttons.

The <FORM> Tag

The form header and the <FORM> tag are actually one and the same. The <FORM> tag takes the six attributes shown in Table 8.1. The ACTION attribute is required in every <FORM> tag.

Table 8.1 Attributes of the <FORM> Tag

Attribute Purpose

ACCEPT Specifies a list of MIME types that the server will process correctly
ACCEPT-CHARSET Provides a list of character sets that are acceptable to the server
ACTION Specifies the URL of the processing script
ENCTYPE Supplies the MIME type of a file used as form input
METHOD=GET|POST Tells the browser how it should send the form data to the server
TARGET Gives the name of the frame where the response from the form submission is to appear

ACTION is set equal to the URL of the processing script so that the browser knows where to send the form data after it is entered. Without it, the browser has no idea where the form data should go. A full ACTION URL has the following form:

protocol://server/path/script_file

You can also use a relative URL if you are calling a script on the same server.

METHOD specifies the HTTP method to use when passing the data to the script and can be set to values of GET or POST. When you’re using the GET method, the browser appends the form data to the end of the URL of the processing script. The POST method sends the form data to the server in a separate HTTP transaction.

METHOD is not a mandatory attribute of the <FORM> tag. In the absence of a specified method, the browser uses the GET method.


CAUTION:  

Some servers might have operating environment limitations that prevent them from processing a URL that exceeds a certain number of characters—typically one kilobyte of data. This limitation can be a problem when you’re using the GET method to pass a large amount of form data. Because the GET method appends the data to the end of the processing script URL, you run a greater risk of passing a URL that’s too big for the server to handle. If URL size limitations are a concern on your server, you should use the POST method to pass form data.




Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.