HTML5 New Form Attributes-Part 3

Formmethod Attribute

 
A string indicating which HTTP method (GET or POST) should be used when submitting; it overrides the method of the <form> element if defined. The formmethod only applies when the type is an image or submit, and the form attribute has been set.
 
If the input element is a submit button or image, this attribute specifies the HTTP method that the browser uses to submit the form. Possible values are:
  • post: The data from the form is included in the body of the form and is sent to the server.
  • get: The data from the form are appended to the form attribute URI, with a "?" as a separator, and the resulting URI is sent to the server. Use this method when the form has no side-effects and contains only ASCII characters.
Purpose: If specified, this attribute overrides the method attribute of the form element.
 
Note: This attribute is supported on input and button elements.
 
Syntax
 
<input type="submit" value="Submit" formmethod="POST">
 
Browser Support
 
It is supported in all major browsers such as Chrome, Safari, Internet Explorer, Firefox and Opera.
 
Example
  1. <!DOCTYPE html>  
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta charset="utf-8" />  
  5.     <title>Formmethod Attribute</title>  
  6. </head>  
  7. <body>  
  8.     <h3>HTML5 Formmethod Attribute</h3>  
  9.     <form action="form.asp" method="get">  
  10.         First name:  
  11.         <input type="text" name="fname"><br>  
  12.         Last name:  
  13.         <input type="text" name="lname"><br>  
  14.         Email:  
  15.         <input type="email" id="email" name="email"><br>  
  16.         <input type="submit" id="Submit" value="Submit">  
  17.         <input type="submit" formmethod="post" value="Send as POST">  
  18.     </form>  
  19. </body>  
  20. </html> 
Output
 
formmethod.jpg
 

Formnovalidate Attribute

 
If the input element is a submit button or image then this Boolean attribute specifies that the form is not to be validated when it is submitted.
 
Useful for a Save for Later button. On the button that saves the form for later. the novalidate attribute is a boolean attribute.
 
Purpose: For overriding the novalidate attribute on the form element.
 
Note: This attribute is supported on input and buttonelements.
 
When To use the novalidate attribute and Formnovalidate Attribute
 
Using novalidate in the opening <form> tag is basically a catch-all way of preventing the form from being validated when it's submitted.
 
The formnovalidate attribute gives you a finer degree of control because it applies only when that particular button is clicked.
 
Syntax
 
<input type="submit" formnovalidate value="Don't validate">
 
Browser Support
 
It is supported in all major browsers such as Chrome, Internet Explorer, Firefox and Opera except Safari.
 
Example
  1. <!DOCTYPE html>  
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta charset="utf-8" />  
  5.     <title>Formnovalidate Attribute</title>  
  6. </head>  
  7. <body>  
  8.     <h3>HTML5 Formnovalidate Attribute</h3>  
  9.     <form action="form.asp">  
  10.         E-mail:  
  11.         <input type="email" name="userid"><br>  
  12.         Number of times:<input type="number" name="num" min="1" max="10"><br>  
  13.         <input type="submit" value="Submit"><br>  
  14.         <input type="submit" formnovalidate value="Don't validate">  
  15.     </form>  
  16. </body>  
  17. </html>   
Output
 
formnovalidate.jpg
 

Formtarget Attribute

 
The Formtarget attribute specifies the target window for form results. It has the same effect as the target attribute on the form element and can only be used with a submit or image button (type="submit" or type="image").
 
It specifies a name or a keyword that indicates where to display the response that is received after submitting the form.
 
Purpose: For overriding the target attribute on the form element.
 
Note: This attribute is supported on input and buttonelements.
 
Syntax
 
<input type="submit" value="Submit"formtarget="_self">
 
Browser Support
 
It is supported in all major browsers such as Chrome, Internet Explorer, Firefox, Opera and Safari.
 
Example
  1. <!DOCTYPE html>  
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4.     <meta charset="utf-8" />  
  5.     <title>Formtarget Attribute</title>  
  6. </head>  
  7. <body>  
  8.     <h3>HTML5 Formtarget Attribute</h3>  
  9.     <form action="form.asp">  
  10.         First name:  
  11.         <input type="text" name="fname"><br>  
  12.         Last name:  
  13.         <input type="text" name="lname"><br>  
  14.         Location:  
  15.         <input type="text" name="name"><br>  
  16.         <input type="submit" value="Submit as normal">  
  17.         <input type="submit" formtarget="_blank" value="Post to a new tab/window">  
  18.     </form>  
  19. </body>  
  20. </html>   
Output
 
formtarget.jpg