The form
element is used to create data entry forms. Data collected in the form is sent to the server for processing by server-side scripts such as PHP, ASP, etc.
<form method="post" action="register.php">
<fieldset>
<legend>Personal information</legend>
<label for="firstname">First name</label><br />
<input type="text" name="firstname" id="firstname" /><br />
<label for="lastname">Last name</label><br />
<input type="text" name="lastname" id="lastname" />
</fieldset>
<fieldset>
<legend>Medical history</legend>
<input name="history" type="checkbox" value="1" id="smallpox" />
<label for="smallpox">Smallpox</label><br />
<input name="history" type="checkbox" value="2" id="mumps" />
<label for="mumps">Mumps</label><br />
<input name="history" type="checkbox" value="3" id="dizziness" />
<label for="dizziness">Dizziness</label>
</fieldset>
</form>
Basic
action
- (URI) Specifies the location of the server-side script used to process data collected in the form.
method
- Specifies the type of HTTP method used to send data to the server. The default is
get
when the form data is sent to the server encoded into the URL specified in the action
attribute. Most forms use post
when form data is sent to the server in the body of the HTTP message.
Advanced
accept
- (ContentTypes) This attribute specifies a comma-separated list of content types that a server processing the form will handle correctly.
accept-charsets
- (Charsets) This attribute specifies the list of character encodings for input data that are accepted by the server processing the form.
enctype
- (ContentType) This attribute specifies the content type used to send form data to the server when the value of
method
is post
. The default value for this attribute is application/x-www-form-urlencoded
. If a form contains a file upload control (input
element with type
value of file
), then this attribute value should be multipart/form-data
. onreset
- (Script) A client-side script event that occurs when a form is reset (all form controls are set to their initial values).
onsubmit
- (Script) A client-side script event that occurs when a form is submitted (form data is sent to server-side scripts for processing).
Common core attributes
class
- (NameTokens) This attribute assigns a class name or set of class names to an element. Any number of elements may be assigned the same class name or set of class names. Multiple class names must be separated by white space characters. Class names are typically used to apply CSS formatting rules to an element.
id
- (ID) This attribute assigns an ID to an element. This ID must be unique in a document. This ID can be used by client-side scripts (such as JavaScript) to select elements, apply CSS formatting rules, or to build relationships between elements.
title
- (Text) This attribute offers advisory information. Some Web browsers will display this information as tooltips. Assistive technologies may make this information available to users as additional information about the element.
Common internationalization attributes
xml:lang
- (NameToken) This attribute specifies the base language of an element's attribute values and text content.
dir
This attribute specifies the base direction of text. Possible values:
ltr
: Left-to-rightrtl
: Right-to-left
Common event attributes
onclick
- (Script) A client-side script event that occurs when a pointing device button is clicked over an element.
ondblclick
- (Script) A client-side script event that occurs when a pointing device button is double-clicked over an element.
onmousedown
- (Script) A client-side script event that occurs when a pointing device button is pressed down over an element.
onmouseup
- (Script) A client-side script event that occurs when a pointing device button is released over an element.
onmouseover
- (Script) A client-side script event that occurs when a pointing device is moved onto an element.
onmousemove
- (Script) A client-side script event that occurs when a pointing device is moved within an element.
onmouseout
- (Script) A client-side script event that occurs when a pointing device is moved away from an element.
onkeypress
- (Script) A client-side script event that occurs when a key is pressed down over an element then released.
onkeydown
- (Script) A client-side script event that occurs when a key is pressed down over an element.
onkeyup
- (Script) A client-side script event that occurs when a key is released over an element.
Common style attribute
style
- (Text) This attribute specifies formatting style information for the current element. The content of this attribute is called inline CSS. The
style
attribute is deprecated (considered outdated), because it fuses together content and formatting.