form Element


 

Module

The form element is a block-level element declared by the XHTML 1.1 Forms Module

Elements in the Forms Module are:
form | label | textarea | select | optgroup | option | button | fieldset | legend |
input type="button" | input type="checkbox" | input type="file" | input type="hidden" | input type="image" | input type="password" | input type="radio" | input type="reset" | input type="submit" | input type="text"

Description

The form element is used to enclose a set of form controls (see the Forms Module for a list of form control elements). These controls allow interaction with the user and include, for example, text boxes to be filled in, buttons to be checked or pressed, options to be selected, and so on. The form element itself provides a container for these controls and specifies:

  • to which URI the enclosed form data should be sent for processing, using the action attribute.
  • the HTTP transmission method, using the method attribute.
  • the content type of the transmitted data, using the enctype attribute.
  • which character sets are accepted at the processing URI, using the accept-charset attribute.
  • for file uploads, which MIME types will be accepted at the processing URI, using the accept attribute.

If you use any file upload controls (see input type="file") within a form you must specify an enctype of "multipart/form-data" and a method of "post".

Form submit buttons can be created using input type="submit", input type="image" or button elements.

A form element may have only block level elements (such as div or p) as children. The form-specific fieldset element may also be used - see the above Content Model for details. The form controls themselves must be placed inside these block children.

Here is a simple example form which contains only a single text input field and a submit button:

<form action="processform.cgi" method="post" accept-charset="utf-8">
<div>
<label for="email">Email Address:</label>
<input type="text" id="email" name="email" size="30" value="Please enter your email address" />
<input type="submit" value="Submit" />
</div>
</form>

The input type="text" form control element creates a text box in which the user can enter arbitrary text to be submitted. This example is rendered below (although the action URI has been altered because processform.cgi does not exist here - pressing the button will just return you to this details section and nothing else will happen - after all, it is just an example!)

#REQUIRED Attributes

The action attribute is #REQUIRED on the form element.


Specific Attributes

Specific attributes of the form element are listed below:

From the Forms Module - the Element's own Module

accept [ type ContentTypes ]
Comma-separated list of one or more content types (e.g. "image/jpeg") which will be accepted and handled correctly by the form's processing script
accept-charset [ type Charsets ]
Space-separated list of one or more accepted character encodings, e.g. "utf-8"
action [ type URI - #REQUIRED ]
URI of the form processor to which the data will be sent - user agent behaviour is undefined if action is given a value other than a URI
enctype [ type ContentType - default="application/x-www-form-urlencoded" ]
For method="post", this specifies the content type of the submitted data. Behaviour for enctype values other than "application/x-www-form-urlencoded" and "multipart/form-data" is unspecified.
method [ type Enumeration (get | post) - default="get" ]
The HTTP method used to submit the form data. If submitting non-ASCII characters, binary data or using input type="file" within the form, method should be "post" with an enctype of "multipart/form-data".

From the Intrinsic Events Module

onreset [ type Script ]
Script to be executed when the form is reset
onsubmit [ type Script ]
Script to be executed on submission of the form

From the Target Module

target [ type FrameTarget ]
Indicates the window or frame in which to open the action URI

Common Attributes

Common attributes of the form element are listed below:

From the Core Attribute Collection

class [ type NMTOKENS ]
One or more space separated classes
id [ type ID ]
A unique identifier for the element
style [ type CDATA ], from the Style Attribute Module (deprecated)
Element-specific styles
title [ type Text ]
Descriptive title for the element (in some user agents this may appear as a "tooltip" when the mouse hovers over the element)
xmlns [ type URI - #FIXED 'http://www.w3.org/1999/xhtml' ]
XML namespace

From the I18N Attribute Collection

dir [ type Enumeration (ltr | rtl) ], from the Bi-directional Text Module
Left-to-right or right-to-left directionality
xml:lang [ type LanguageCode ]
A language code for the element

From the Events Attribute Collection

All attributes in the Events Attribute Collection are supported:
onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup


Content Model

The Content Model for the form element is:

( BlkNoForm.mix | fieldset )+

NOTE: This element cannot be empty

See Content Model & Nesting for information about Content Model syntax and Nesting Groups.

Valid children of form

Note: A form element must never contain another form element, at any nesting depth. See Descendant Exclusions.

Valid parents of form


Page Footer & Copyright

Copyright © Sally Maughan 2005-2009 (Page last updated on 01 Oct 2009)

*Valid XHTML 1.1 - hosted by *Openstrike

Content based on the W3C Working Draft: *XHTML 1.1 and Recommendation: *XHTML Modularisation 1.1.

W3C, XHTML, XML, HTML, CSS and MathML are *Trademarks of the W3C (*MIT, *ERCIM, *Keio) with which the site's author has no connection.


Up, Next & Previous Links

Your Location

Home > XHTML 1.1 Home > XHTML 1.1 Indexes > Element Index (XHTML 1.1) > form Element