input ( type=submit ) element
If you don’t know what an element is or how you must use it, I recommend you read the » HTML tags and attributes» tutorial that you can find in the HTML tutorials section.
Description
The input element, having the «submit» value in its type attribute, represents a button that, when pressed, submits the form it belongs to.
With the arrival of HTML 5, several new attributes have been added to this element ( formaction , formenctype , formmethod , formnovalidate and formtarget ) that define and override certain parameters pertaining how the form must be submitted. These new attributes can be used, for example, to provide more than one submit button in one form , and make each of them perform a different type of submission.
The value attribute has a particular meaning for this element: it represents the label of the button, that is usually shown by browsers inside of it.
Examples
In our first example we’ll create a basic form with a couple of fields and a submit button. Here you’ll be able to see and test the functionality of the submit button: when you press it, the form is automatically submitted.
action="../../form-result.php" method="post" target="_blank"> Username: type="text" name="user"> Password: type="password" name="pass"> type="submit" value="Send data">
Now, we’ll provide two submit buttons in the same form , and we’ll make each perform a different type of submission. While the first button uses the default configuration declared in the form element, the second overrides some of the original attributes and produces a submission using the GET method, with no validation of data.
action="../../form-result.php" method="post" target="_blank"> Username: type="text" name="user" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]$" title="A proper username must begin with a letter, contain letters, numbers, scores and stops, and have between 3 and 15 characters long" required> Password: type="password" name="pass" pattern="[a-zA-Z0-9]" title="A valid password must be composed by letters and/or numbers and have a length between 6 and 15 characters" required> type="submit" value="Send"> type="submit" value="Send without validation" formmethod="get" formnovalidate>
Attributes
Specific attributes
autofocus
A boolean value instructing the browser to set the focus to this control when the document has finished loading or when the dialog where the control finds itself is shown. If the attribute has the value «autofocus» or the empty string («»), or if it’s just present, the control should get the focus as soon as possible, after the page or dialog has been loaded.
type="submit" value="Send data" autofocus>
disabled
A boolean value indicating wether the control is disabled or not. If the attribute takes the value «disabled» or the empty string («»), or if it’s just present, the control will be disabled.
Disabled controls are rendered greyed out (if visible), are blocked from user interaction and, more importantly, their values (if any) aren’t sent when the form is submitted.
action="../../form-result.php" method="post" target="_blank"> Key word: type="text" name="keyword"> type="submit" value="Send data" disabled>
form
The value of the id attribute of the form with which this control is associated to.
This attribute is new in HTML 5 and helps defining the pertenence of controls in nested or distant forms.
>"form1" action="../../form-result.php" method="post" target="_blank"> Surname: type="text" name="surname"> type="submit" value="Send data" form="form1">
formaction
A URI indicating the location of the script responsible for the manipulation of the data sent by the form . This script is usually written in a server-side language like ASP , PHP , Python, etc.
This attribute is new in HTML 5 and, if present, overrides the action attribute of the form element. This allows authors to provide one form with two or more buttons that perform different types of submissions.
method="post" target="_blank"> Nombre: type="text" name="nombre"> type="submit" value="Enviar datos" formaction="../../form-result.php">
formenctype
A value indicating the encoding method to be used for data when the form is submitted. There are three possible case-insensitive values:
- application/x-www-form-urlencoded: spaces are replaced with plus signs («+») and special characters are converted to HEX values. This is the default value.
- multipart/form-data: no encoding is performed. This value is necessary for file uploads.
- text/plain: only spaces are replaced by plus signs («+»).
Remember you must use the value «multipart/form-data» whenever a file is going to be uploaded in the form. Without this configuration, file uploads will fail.
This attribute is new in HTML 5 and, if present, overrides the action attribute of the form element. This allows authors to provide one form with two or more buttons that perform different types of submissions.
action="../../form-result.php" target="_blank"> Full name: type="text" name="fullname"> Picture: type="file" name="picture"> type="submit" value="Send with picture" formenctype="multipart/form-data"> type="submit" value="Send without picture">
formmethod
The method browsers should use to send the form’s data. There are three possible case-insensitive values:
- get: data is attached to the URL of the request (the one provided in the action attribute). The name-value pairs are arranged in the form «name=value» and separated each other with an ampersand sign («&»). All this string is appended to the request URL preceded by a question mark («?»). For example, a GET string could be: «form-result.php?user=john&pass=123456»
- post: data is attached to the body of the request.
- dialog: specific for forms inside a dialog element. Instructs the browser to close the dialog box upon form submission. Form results should be handled by scripts.
This attribute is new in HTML 5 and, if present, overrides the action attribute of the form element. This allows authors to provide one form with two or more buttons that perform different types of submissions.
action="../../form-result.php" target="_blank"> City: type="text" name="city"> type="submit" value="Send with GET" formmethod="get"> type="submit" value="Send with POST" formmethod="post">
formtarget
A value specifiyng where the results of the script in charge of processing the data should be loaded. This value can be a browsing-context name (like the value of the name attribute of an iframe ) or any of the following values (case-insensitive):
- _blank: in a new window/tab.
- _parent: in the immediate parent context.
- _self: in the same context that’s containing the form.
- _top: in the topmost context (the greatest parent context containing the form).
This attribute is new in HTML 5 and, if present, overrides the action attribute of the form element. This allows authors to provide one form with two or more buttons that perform different types of submissions.
action="../../form-result.php" method="post"> Group: type="text" name="group"> type="submit" value="Submit" formtarget="_blank">
formnovalidate
A boolean value instructing the browser not to validate the form’s data upon submission. If this attribute takes the value «formnovalidate» or the empty string («»), or if it’s just present, the browser should omit the form’s validation during submission.
This attribute is new in HTML 5 and, if present, overrides the action attribute of the form element. This allows authors to provide one form with two or more buttons that perform different types of submissions.
This attribute is part of the Constraint Validation API , a new feature that allows authors to provide form validation with minimal programming intervention.
action="../../form-result.php" target="_blank"> Username: type="text" name="user" pattern="^[a-zA-Z][a-zA-Z0-9-_\.]$" title="A proper username must begin with a letter, contain letters, numbers, scores and stops, and have between 3 and 15 characters long" required> type="submit" value="Send"> type="submit" value="Send without validating" formnovalidate>
name
A name for the control. This name will be sent by the browser to the processing agent, paired with the content of the value attribute. Both attributes together will conform a name-value pair that will be used to process the form data.
Currently, the value isindex , formerly used in a special way by some browsers and included in the HTML standard, isn’t permitted in this attribute.
The name-value pair of a button is submitted, with the other form data, only if the button has been used to submit the form.
action="../../form-result.php" method="post" target="_blank"> Partner name: type="text" name="partnername"> type="submit" name="submitbutton" value="Submit">
type
A value indicating the type of the field that this element represents. There are twenty two possible values (case-insensitive):
- hidden: a hidden control used to send information to the server, typically managed by scripts.
- text: a control used to input a single-line piece of text.
- search: same as text but for search purposes.
- tel: a control used to provide a telephone number.
- url: a text box used to input a single and absolute URL .
- email: a control designed to edit one or more e-mail addresses.
- password: a text box for editing passwords, where the characters are represented by dots.
- date: a control to input a specific date.
- month: a control to input a specific month.
- week: a control to input a specific week.
- time: a control to input a specific time.
- datetime-local: a control to input a specific local date and time.
- number: a control to input a number.
- range: a control to input one or two numbers inside a range.
- color: a control to input a color.
- checkbox: a control to input a boolean value (true/false).
- radio: a control used to choose one single option among many.
- file: a control used to upload files to the server.
- submit: a button used to submit the form.
- image: same as submit but with the ability to be shown as an image instead of using the default button appearance.
- reset: a button used to reset the form’s controls to their default values.
- button: a button with no default action associated.
When this attribute isn’t present, the element behaves as it would have the value «text».
type="submit" value="Submit data">
value
A value for the control. This value will be sent by the browser to the processing agent, paired with the content of the name attribute. Both attributes together will conform a name-value pair that will be used to process the form data.
Additionally, browsers will use the content of this attribute as a label for the button.
The name-value pair of a button is submitted, with the other form data, only if the button has been used to submit the form.
Processing agents will find little use in the name-value pair passed by a button. Instead, the value attribute has a more important task providing the label that browsers will display as content of the button.
action="../../form-result.php" method="post" target="_blank"> Search: type="search" name="searchstring" value="Autum"> type="submit" name="submitbutton" value="Search">
Global attributes
For information about global attributes refer to this list of global attributes in HTML 5.
Events
Global events
For information about global events refer to this list of global events in HTML 5.