Skip to main content

HTML Input form* Attributes

This chapter describes the different form* attributes you can use on the HTML <input> element. These are extra attributes whose names start with form, and most of them let a single button override a setting on the form it belongs to.


The form Attribute

The form attribute says which form an <input> belongs to. Set its value to the id of the <form>. This lets an input sit outside the form in the page but still be sent with it.

Example

A field placed outside the form that still belongs to it through the form attribute.

Prompt
A page with a form (id="form1", action /action_page.php) holding a First name field and submit button, plus a Last name field placed OUTSIDE the form that still belongs to it via the form="form1" attribute.
Output: complete HTML page

The formaction Attribute

The formaction attribute sets the URL of the file that will handle the input when the form is submitted.

Note: It overrides the form's own action attribute. It works with the submit and image input types.

Example

A form with two submit buttons that send the data to different URLs.

Prompt
A form (action /action_page.php) with First name and Last name fields and two submit buttons: a normal "Submit", and a "Submit as Admin" button whose formaction="/action_page2.php" overrides the form's action.
Output: complete HTML page

The formenctype Attribute

The formenctype attribute sets how the form data should be encoded when it is sent (only for forms using method="post").

Note: It overrides the form's own enctype attribute. It works with the submit and image input types.

Example

A form with two submit buttons: one uses the default encoding, the other sends the data as multipart/form-data.

Prompt
A form (action /action_page_binary.asp, method post) with a First name field and two submit buttons: one with default encoding, and one whose formenctype="multipart/form-data" overrides the form's encoding.
Output: complete HTML page

The formmethod Attribute

The formmethod attribute sets the HTTP method used to send the form data to the action URL.

Note: It overrides the form's own method attribute. It works with the submit and image input types. The data can be sent as URL variables with GET or as an HTTP post with POST.

Notes on GET: it adds the data to the URL as name/value pairs, is handy when the user wants to bookmark the result, and has a URL length limit, so not all data may transfer. Never use GET for sensitive information, since it shows in the address bar.

Notes on POST: it sends the data as an HTTP post, which cannot be bookmarked. POST is more robust and secure than GET and has no size limit.

Example

A form with two submit buttons, one sending with GET and one with POST.

Prompt
A form (action /action_page.php, method get) with First name and Last name fields and two submit buttons: "Submit using GET", and "Submit using POST" whose formmethod="post" overrides the form's method.
Output: complete HTML page

The formtarget Attribute

The formtarget attribute sets a name or keyword for where to show the response received after the form is submitted.

Note: It overrides the form's own target attribute. It works with the submit and image input types.

Example

A form with two submit buttons that show the response in different windows.

Prompt
A form (action /action_page.php) with First name and Last name fields and two submit buttons: a normal "Submit", and one whose formtarget="_blank" opens the response in a new window or tab.
Output: complete HTML page

The formnovalidate Attribute

The formnovalidate attribute says that an <input> should not be validated when the form is submitted.

Note: It overrides the form's own novalidate attribute. It works with the submit input type.

Example

A form with two submit buttons, one of which skips validation.

Prompt
A form (action /action_page.php) with an email field and two submit buttons: a normal "Submit", and a "Submit without validation" button whose formnovalidate attribute skips validation.
Output: complete HTML page

The novalidate Attribute

The novalidate attribute is a <form> attribute. When it is present, none of the form data is validated when the form is submitted.

Example

A form set so that no form data is validated on submit.

Prompt
A form (action /action_page.php) with the novalidate attribute set on the form itself, containing an email field and a submit button, so none of the form data is validated on submit.
Output: complete HTML page