Click Here!
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.

HTML 4.0 Sourcebook
(Publisher: John Wiley & Sons, Inc.)
Author(s): Ian S. Graham
ISBN: 0471257249
Publication Date: 04/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


FORM encompasses the content of an HTML fill-in form. This is the element you use to create fill-in forms containing checkboxes, radio boxes, text input windows, and buttons. Data from a FORM must be sent to server-side gateway programs for processing, since a FORM collects data, but does not process it. In general, a FORM and the server-side program handling the FORM output must be designed together so that the program understands the data being sent from the FORM. Some simple examples showing the variety of possible FORMs are shown in Figures 6.21 through 6.24. Note that FORMs do not nest—you cannot have a FORM within a FORM.

The FORM element takes three main attributes. These determine where the FORM input data is to be sent (ACTION); what HTTP protocol to use when sending the data (METHOD); and the data type of the content (ENCTYPE).


Figure 6.17 Document employing FONT and text highlighting elements to modify the presentation of form INPUT elements. See also Figure 6.18.

<HTML><HEAD>
<TITLE>Test of FONT and form INPUT Elements</TITLE>
</HEAD><BODY BGCOLOR=“white”>
<FORM ACTION=“accesskey.htm”>
<P><B>Three buttons: (1) Normal, &nbsp; 
     (2) Arial Font, &nbsp;  (3) Bold + Arial font, &nbsp; 
and (4) Superscript</B></P>

	<INPUT TYPE=“button” NAME=“y” VALUE=“Button 1”>
<FONT FACE=“arial”>
     <INPUT TYPE=“button” NAME=“y” VALUE=“Button 2”>
</FONT>
<FONT FACE=“arial”>
     <B><INPUT TYPE=“button” NAME=“y” VALUE=“Button 3”></B>
</FONT>
   <SUP><INPUT TYPE=“button” NAME=“y” VALUE=“Button 4”></SUP>
<BR>
<BR>
<INPUT TYPE=“text” NAME=“f”
       VALUE=“12345678901234567890”>        ... <B>Standard Text Box</B><BR>
<B><INPUT TYPE=“text” NAME=“f”
	  VALUE=“12345678901234567890”></B> ... <B>Boldface</B><BR>
<FONT FACE=“arial” SIZE=“+1”>                      
     <INPUT TYPE=“text” NAME=“f”
	    VALUE=“12345678901234567890”></FONT>
					     ... <B>Arial Font,
						  SIZE=“+1”</B><BR>      
</FONT>
<FONT FACE=“courier new” SIZE=“-1”>                      
     <INPUT TYPE=“text“ NAME=”f”
	    VALUE=“12345678901234567890”></FONT>
					     ... <B>Courier New Font,
						  SIZE=“-1”</B><BR>      
</FORM>
</BODY>
</HTML>


Figure 6.18  Rendering by Netscape Navigator 3 (top), Internet Explorer 4 (middle), and Netscape Navigator 4 (bottom) of the document listed in Figure 6.17. Note how Internet Explorer 4 largely ignores HTML-based formatting when applied to form INPUT elements.

There are several additional attributes that provide additional functionality. All these attributes are described in the following:

ACCEPT-CHARSET=“string” (optional; not currently supported) Specifies the list of allowed character set encodings that the server, referenced by the ACTION, will accept. The value is a space- or comma-separated list of character set names—see Appendix A on the companion Web site for details on character set names and character encodings. The default value is “UNKNOWN,” in which case the browser should encode data typed into the browser using the same character encoding used in the document containing the form. This attribute is not currently supported.
ACTION=“url” (mandatory) Specifies the URL to which the FORM content is to be sent. Usually this is a URL pointing to a program on an HTTP server, since only HTTP servers allow significant interaction between the client and the server. However, the ACTION can specify other URLs. For example, in the case of a mailto URL, the FORM content could be mailed to the indicated address. In this case, the METHOD must be set to “POST.”
Action is formally mandatory, but if is omitted, some browsers (e.g., Netscape but not Internet Explorer) will attempt to recontact the URL from which the document containing the form was retrieved and will use the specified ENCTYPE and METHOD to encode and send the data.


Figure 6.19 Document employing CSS rules to modify the presentation of form input elements. See also Figure 6.20.

<HTML><HEAD>
<TITLE>CSS Rules Applied to FORM Elements</TITLE>
<STYLE>
.b2 {font-family: Arial;         color: red}
.b3 {font-family: Arial;         font-weight: bold}
.t2 {font-weight: bold; }
.t3 {font-family: Arial;         font-size: 125%;}
.t4 {font-family: “courier new”; font-size: 75%}
</STYLE>
</HEAD>
<BODY BGCOLOR=“white”>
<FORM ACTION=“accesskey.htm”>

<INPUT TYPE=“button” CLASS=“b1” NAME=“y” VALUE=“Button 1”>
<INPUT TYPE=“button” CLASS=“b2” NAME=“y” VALUE=“Button 2”>
<INPUT TYPE=“button” CLASS=“b3” NAME=“y” VALUE=“Button 3”>

<BR>
<BR>
<INPUT CLASS=“t1” TYPE=“text” NAME=“f”
       VALUE=“12345678901234567890”>    ... <B>Standard Text Box</B><BR>
<INPUT CLASS=“t2” TYPE=“text” NAME=“f”
       VALUE=“12345678901234567890”>    ... <B>Boldface</B><BR>
<INPUT CLASS=“t3” TYPE=“text” NAME=“f”
       VALUE=“12345678901234567890”>    ... <B>Arial Font, and
						  bigger </B><BR>
<INPUT CLASS=“t4” TYPE=“text” NAME=“f”
       VALUE=“12345678901234567890”>    ... <B>Courier New Font,
						  smaller </B><BR>
</FORM>
</BODY></HTML>
METHOD= “GET” or “POST” (optional) Specifies the METHOD for sending the data, the default value being GET. When ACTION indicates an http URL, the METHOD is just the HTTP method for sending information to the server. HTTP methods are discussed in Chapter 9. With GET, the content of the form is then appended to the URL in a manner similar to query data from an ISINDEX search (as discussed in Chapter Figure 6.20 Rendering by Netscape Navigator 4 (top) and Internet Explorer 4 (bottom) of the document listed in Figure 6.19. 10). With the POST method, the data are sent to the server as a message body and encoded as specified by the ENCTYPE attribute value. The situation with mailto URLs is not fully specified—in practice you must specify METHOD=“POST,” and the data are sent as a mail message body and encoded as specified by ENCTYPE. Some browsers do not support mailto URLs in FORMs.
ENCTYPE=mime-type” (optional) Specifies the MIME-type encoding used for data sent via the POST method. The default value is “application/x-www-form-urlencoded.” The only other supported value is “multipart/form-data.” These encoding formats are described in Chapters 8 and 9.
NAME=string” (optional) Specifies a symbolic name by which the form can be addressed from within a script program. For example, if a FORM element has the attribute NAME=“myForm,” then this form can be referenced, from JavaScript, using the notation document.myForm. Note that JavaScript treats NAME values as case-sensitive, while VBScript treats these values as case-insensitive. ID values can in principle be used instead of NAMEs; however, Netscape Navigator does not support ID values for this purpose.
TARGET=“string” (optional) Specifies the name of the frame or window to which the data returned by the submitted form should be sent. This attribute is used to the same purpose with the A (anchor) element. Please see the anchor (A) element section for further details. This attribute is supported by all browsers that support FRAMES.


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.