form
Summary
The form element (<form>) defines an HTML form for user input, subsequently to be submitted to a website or service.
Overview Table
Attributes
accept-charset
= list of character-encoding names
gives the character encodings that are to be used for the submission.action
= valid URL potentially surrounded by spaces
Specify the form-submission action for the element.autocomplete
= on/ off
Specifies whether the element represents a form for which by default a UA is meant to store the values entered into its input elements by the user (so that the UA can pre-fill the form later).- on
The on state indicates that the value is not particularly sensitive and the user can expect to be able to rely on his user agent to remember values he has entered for that control. - off
The off state indicates either that the control’s input data is particularly sensitive (for example the activation code for a nuclear weapon); or that it is a value that will never be reused (for example a one-time-key for a bank login) and the user will therefore have to explicitly enter the data each time, instead of being able to rely on the UA to prefill the value for him; or that the document provides its own autocomplete mechanism and does not want the user agent to provide autocompletion values.
- on
enctype
= application/x-www-form-urlencoded / multipart/form-data / text/plain
Specfy a MIME type with which a UA is meant to associate this element for form submission.
The missing value default for these attributes is the application/x-www-form-urlencoded state.- application/x-www-form-urlencoded
- multipart/form-data
- text/plain
method
= get/ post
Specify the HTTP method with which a UA is meant to associate this element for form submission.
The missing value default for this attributes is the GET state.- get
Indicating the HTTP GET method. - post
Indicating the HTTP POST method.
- get
name
= string
Gives the name of the input element.novalidate
= boolean
If present, they indicate that the form is not to be validated during submission.target
= valid browsing context names or keywords
Specfy a browsing context name or keyword that represents the target of the control.
Examples
This example uses the form element to create a basic form containing a text entry box for the user’s name and a select control for choosing a favorite ice cream flavor. When the user clicks the Submit button, the form sends the data to the URL listed in the action attribute. The value of the method attribute determines how to send the data to the server.
<form action="http://example.microsoft.com/sample.asp" method="post">
Enter your name: <input name="FName"/><br/>
Favorite Ice Cream Flavor:
<select name="Flavor">
<option value="Chocolate">Chocolate</option>
<option value="Strawberry">Strawberry</option>
<option value="Vanilla" selected="selected">Vanilla</option>
</select>
<p><input type="submit"/></p>
</form>
Notes
Remarks
**Security Warning: **Using this object incorrectly can compromise the security of your application. Data submitted through a form using the HTTP protocol is not encrypted and can be read and possibly tampered with in transmission. The Secure Hypertext Transfer Protocol (HTTPS) can provide more secure data transmission. You should review the Security Considerations: Dynamic HTML before continuing. Forms enable client-side users to submit data to a server in a standardized format. The creator of a form designs it to collect the required data using a variety of controls, such as input or select. Users viewing the form fill in the data and then click the Submit button to send the data to the server. A script on the server then processes the data. Each control element’s name attribute must be defined if the data is to be submitted with the form. An element in a form can be referenced by the name property or the id property, or through the elements collection. When the focus is on a control in a form and the user presses ESC, the value of the control reverts to the last value. The form resets if the user presses ESC again. If the form includes only one text box and the user presses ENTER, the onsubmit event fires. If the form has an input type="submit" element, it will appear as a button with a dark border, which indicates the user can press ENTER to submit the form. Windows Internet Explorer 8 and later. The value of the action attribute depends on the current document compatibility mode. In addition, the form object now supports enctype as a DOM attribute.
Related specifications
See also
Related pages
- 1,001 Ways to Get Input from Web Users1,001 Ways to Get Input from Web Users
}
}
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]