Input Form Attributes
HTML Input form* Attributes
Form-related input attributes allow an <input> element to control or override how a form behaves when it is submitted.
The form Attribute
The form attribute associates an input element with a specific form, even if the input is placed outside the form.
The value must match the id of the target <form>.
<form action="/action_page.php" id="form1"> <label for="fname">First name:</label> <input type="text" id="fname" name="fname"><br><br> <input type="submit" value="Submit"> </form> <label for="lname">Last name:</label> <input type="text" id="lname" name="lname" form="form1">
The formaction Attribute
The formaction attribute defines the URL that processes the form data.
It overrides the action attribute of the <form>.
Works with: submit, image.
<form action="/action_page.php"> <input type="submit" value="Submit"> <input type="submit" formaction="/action_page2.php" value="Submit as Admin"> </form>
The formenctype Attribute
The formenctype attribute specifies how form data is encoded when submitted.
It overrides the enctype attribute of the form and works only with method="post".
Works with: submit, image.
<form action="/action_page_binary.asp" method="post"> <input type="submit" value="Submit"> <input type="submit" formenctype="multipart/form-data" value="Submit as Multipart"> </form>
The formmethod Attribute
The formmethod attribute defines which HTTP method is used to send the form data.
It overrides the method attribute of the form.
Works with: submit, image.
<form action="/action_page.php" method="get"> <input type="submit" value="Submit using GET"> <input type="submit" formmethod="post" value="Submit using POST"> </form>
The formtarget Attribute
The formtarget attribute specifies where the response will be displayed.
It overrides the target attribute of the form.
Works with: submit, image.
<form action="/action_page.php"> <input type="submit" value="Submit"> <input type="submit" formtarget="_blank" value="Submit to a new window"> </form>
The formnovalidate Attribute
The formnovalidate attribute disables validation for a specific submit button.
It overrides the novalidate attribute of the form.
Works with: submit.
<form action="/action_page.php"> <label for="email">Enter your email:</label> <input type="email" id="email" name="email"><br><br> <input type="submit" value="Submit"> <input type="submit" formnovalidate value="Submit without validation"> </form>
The novalidate Attribute
The novalidate attribute belongs to the <form> element.
When present, the browser skips validation for all inputs in the form.
<form action="/action_page.php" novalidate> <label for="email">Enter your email:</label> <input type="email" id="email" name="email"><br><br> <input type="submit" value="Submit"> </form>
HTML Form and Input Elements
<form>– defines an HTML form for user input<input>– defines an input control