Syntax
<FORM>...</FORM>
Attribute Specifications
ACTION=
URI (form handler)
METHOD=[ get | post ] (HTTP method for submitting form)
ENCTYPE=ContentType (content type to submit form as)
ACCEPT-CHARSET=Charsets (supported character encodings)
TARGET=FrameTarget (frame to render form result in)
ONSUBMIT=Script (form was submitted)
ONRESET=Script (form was reset)
common attributes
Contents:
In HTML 4.0 Strict, one or more SCRIPT or Block-level elements except FORM
In HTML 4.0 Transitional, Inline elements or Block-level elements except FORM
Contained in:
APPLET, BLOCKQUOTE, BODY, CENTER, DD, DEL, DIV, FIELDSET, IFRAME, INS, LI, MAP, NOFRAMES, NOSCRIPT, OBJECT, TD, TH

The FORM element defines an interactive form. The element should contain form controls--
INPUT, SELECT, TEXTAREA, and BUTTON--through which the user interacts.

When the user submits the form, through an INPUT or BUTTON element with TYPE=submit, the form values are submitted to the URI given in FORM's required ACTION attribute. ACTION usually points to a CGI script or Java servlet that handles the form submission.

Example:

<form action="http://www.yourserver.co.uk/cgi/formmail.cgi" method="POST"">
Please select who you would like to send this enquiry to:<BR>
<select name="recipient">
<option name="enquiries" value="enquiries@yourserver.co.uk">Enquiries
<option name="webmaster" value="webmaster@yourserver.co.uk">Webmaster
</select><br>
<input type="hidden" name="subject" value="From the eluk contacts page">
<input type="hidden" name="redirect" value="http://www.eluk.co.uk/next.htm">
Your Full Name<br>
<input NAME="realname" type="textbox" size="40"><br>
Email address<br>
<input name="email" type="textbox" value="" size=40> <br>
Home or business address
<select name="Content">
<option value="Home">Home
<option value="Business">Business
<option value="Other">Other
</select><br>
<input NAME="House Name/Number" type="textbox" value="" size="40"><br>
<input name="street" type="textbox" value="" size="40"> Street <br>
<input name="town" type="textbox" value="" size="40"> Town <br>
<input name="city" type="textbox" value="" size="40"> City<br>
<input name="county" type="textbox" value="" size=40> County<br>
<input name="Post/Zip Code" type="textbox" value="" size="10"> Post/Zip code<br>
<input name="Country" type="textbox" value="" size="40"> Country<br>
<input name="Tel" type="textbox" value size="40"> Telephone Number<br>
<input name="Fax" type="textbox" value size="40"> Fax Number <br>
I am interested in the following services<br>
<input type="checkbox" name="services required 1" value="Email Facilities"> Advertising on eluk<br>
<input type="checkbox" name="services required 2" value="Link from eluk to existing website"> Link from eluk to existing website<br>
<input type="checkbox" name="services required 3" value="Report a problem"> Report a problem<br>
<input type="radio" name="services" value="I think this site is great"> I think this site is great<br>
<input type="radio" name="services" value="I think this site is OK"> I think this site is OK<br>
<input type="radio" name="services" value="I think this site is rubish"> I think this site is rubish<br>
Other please specify <input name="other services" type="textbox" value=""><br>
Comments:<br><textarea rows=5 cols="32" name="Comments"></textarea><br>
Thank you for taking the time to fill out application. Please click 'Submit' once and you enquiry will be looked into as soon as possible.
<br>
<input type="submit" value="Submit"><input type="reset" value="Clear">
</form>

would be displayed like this:

Please select who you would like to send this enquiry to:

Your Full Name

Email address

Home or business address

Street
Town
City
County
Post/Zip code
Country
Telephone Number
Fax Number
I am interested in the following services
Advertising on eluk
Link from eluk to existing website
Report a problem
I think this site is great
I think this site is OK
I think this site is rubish
Other please specify
Comments:

Thank you for taking the time to fill out application. Please click 'Submit' once and you enquiry will be looked into as soon as possible.

A mailto URI (e.g., mailto:simon@eluk.co.uk) is also allowed as an ACTION, but this is not supported by all browsers. Non-supporting browsers such as Microsoft Internet Explorer 3.x typically will open a blank e-mail message when the user submits a mailto form. Even on supporting browsers, mailto forms are troublesome in that they fail to provide feedback to the user after the form submission.

Free CGI scripts exist for handling forms; some are even remotely hosted for authors whose providers refuse to allow CGI scripts to be run locally.

How the form input is sent to the server depends on the METHOD and ENCTYPE attributes. When the METHOD is get (the default), the form input is submitted as an HTTP GET request with ?form_data appended to the URI specified in the ACTION attribute.

Using the get method allows the form submission to be contained completely in a URL. This can be advantageous in that it permits bookmarking in current browsers, but it also prevents form data from containing non-ASCII characters such as "é" and "©". As well, the amount of form data that can be handled by the get method is limited by the maximum length of the URL that the server and browser can process. To be safe, any form whose input might contain non-ASCII characters or more than 100 characters should use METHOD=post.

With a METHOD value of post, the form input is submitted as an HTTP POST request with the form data sent in the body of the request. Most current browsers are unable to bookmark POST requests, but POST does not entail the character encoding and length restrictions imposed by GET.

The ENCTYPE attribute specifies the content type used in submitting the form, and defaults to application/x-www-form-urlencoded. This content type results in name/value pairs sent to the server as name1=value1&name2=value2... with space characters replaced by "+" and reserved characters (like "#") replaced by "%HH" where HH is the ASCII code of the character in hexadecimal. Line breaks are encoded as "%0D%0A"--a carriage return followed by a line feed.

Authors should generally only use a different ENCTYPE when the form includes a TYPE=file INPUT element, in which case the ENCTYPE should be multipart/form-data and the METHOD must be post. The format of multipart/form-data requests is given in RFC 1867.

Tools such as cg-eye allow authors to easily create and view a request, simulating the submission of a form. However, authors often do not need to concern themselves with the exact format of the submission; CGI libraries including CGI.pm transparently handle get and post submissions sent as application/x-www-form-urlencoded or multipart/form-data.

The ACCEPT-CHARSET attribute specifies a list of character encodings that are accepted by the form handler. The value consists of a list of "charsets" separated by commas and/or spaces. The default value is UNKNOWN and is usually considered to be the character encoding used to transmit the document containing the FORM.

The TARGET attribute is used with frames to specify in which frame the form response should be rendered. If no frame with such a name exists, the response is rendered in a new window unless overridden by the user. Special frame names begin with an underscore:

_blank renders the response in a new, unnamed window
_self renders the response in the current frame (useful for overriding a BASE TARGET)
_parent renders the response in the immediate FRAMESET parent
_top renders the response in the full, unframed window

The FORM element also takes a number of attributes to specify client-side scripting actions for various events. In addition to the core events common to most elements, INPUT accepts the following event attributes:

ONSUBMIT, when the form is submitted;
ONRESET, when the form is reset.