Read HTML The Definitive Guide Online
Authors: Chuck Musciano Bill Kennedy
This powerful mechanism has far-reaching implications, particularly for electronic commerce. It finishes an online catalog by giving buyers a way to immediately order products and services. It gives nonprofit organizations a way to sign up new members. It gives market researchers a way to collect user data. It gives you an automated way to interact with your HTML document readers.
Mull over the ways you might want to interact with your readers while we take a look at both the client-and server-side details of creating forms.
10.1 Form Fundamentals
Forms are comprised of one or more text input boxes, clickable buttons, multiple-choice checkboxes, and even pulldown menus and image maps, all placed inside the
Function:
Defines a form
Attributes:
ACCEPT-CHARSET ONKEYPRESS
ACTION ONKEYUP
CLASS ONMOUSEDOWN
DIR ONMOUSEMOVE
ENCTYPE ONMOUSEOUT
ID ONMOUSEOVER
LANG ONMOUSEUP
METHOD ONRESET
NAME
ONSUBMIT
ONCLICK STYLE
ONDBLCLICK TARGET
ONKEYDOWN TITLE
End tag:
; never omitted
Contains:
form_content
Used in:
block
Browsers flow the special form elements into the containing paragraphs as if they were small images embedded into the text. There aren't any special layout rules for form elements, so you need to use other HTML elements, like tables and style sheets, to control the placement of elements within the text flow.
You must define at least two special form attributes, which provide the name of the form's processing server and the method by which the parameters are to be sent to the server. A third, optional attribute lets you change how the parameters get encoded for secure transmission over the network.
10.2.1 The action Attribute
The required action attribute for the
Most webmasters keep their forms-processing applications in a special directory on their web server, usually named
cgi-bin
, which stands for Common Gateway Interface-binaries.[
2
] Keeping these special forms-processing programs and applications in one directory makes it easier to manage and secure the server.
[2] The Common Gateway Interface (CGI) defines the protocol by which servers interact with programs that process form data.
A typical
The example URL tells the browser to contact the web server named
www
in the
kumquat.com
domain and pass along the user's form values to the application named
update
located in the
cgi-bin
directory.
In general, if you see a URL that references a document in a directory named
cgi-bin
, you can be pretty sure that the document is actually an application that creates the desired page dynamically each time it's invoked.
10.2.2 The enctype Attribute
The browser specially encodes the form's data before it passes that data to the server so that it does not become scrambled or corrupted during the transmission. It is up to the server either to decode the parameters or to pass them, still encoded, to the application.
The standard encoding format is the Internet Media Type "application/x-www-form-urlencoded." You can change that encoding with the optional enctype attribute in the
The multipart/form-data alternative is required for those forms that contain file-selection fields for upload by the user. The text/plain format should be used in conjunction with a mailto URL in the action attribute for sending forms to an email address instead of a server. Unless your forms need file-selection fields or you must use a mailto URL in the action attribute, you probably should ignore this attribute and simply rely upon the browser and your processing server to use the default encoding type.
[File selection controls, 10.5.1.3]