HTML formmethod Attribute
Description
The formmethod
attribute in HTML is used to specify the method by which the form data should be submitted to the server. It can be applied to <button>
or <input>
elements within a form, overriding the default or specified method attribute of the form element itself. This attribute provides flexibility in defining submission behaviors for specific buttons or input elements within the same form.
The formmethod
attribute provides an easy way to configure different submission methods for multiple submit buttons within the same form, allowing for more complex interactions and behaviors in web forms.
Syntax
<tagname type="submit" formmethod="get | post">
Values
- getThis value specifies that the form data should be appended to the form's
action
URL, with the fields in the form becoming parameters in the query string of the URL. TheGET
method is typically used for form submissions where the user is requesting data from the server, without intending to create or update resources. - postThis value indicates that the form data should be included in the body of the HTTP request. The
POST
method is commonly used for form submissions that create or update data on the server because it does not expose the form data in the URL, offering a more secure way of transmitting sensitive information.
Applies To
The formmethod
attribute can be used on the following html elements.
Example
<form action="formscript.php" method="get">
Name: <input type="text" name="username"><br><br>
Email: <input type="email" name="email"><br><br>
<input type="submit" value="Submit (GET)"><br><br>
<input type="submit" value="Submit (POST)" formmethod="post">
</form>
Browser Support
The following table will show you the current browser support for the HTML formmethod
Attribute.
Desktop | |||||
Yes | Yes | Yes | Yes | Yes |
Tablets / Mobile | |||||
Yes | Yes | Yes | Yes | Yes | Yes |
Last updated by CSSPortal on: 29th March 2024