What is the formmethod attribute in HTML5?
The formmethod attribute in HTML5 specifies the HTTP method for a button's form submission, overriding the form's method attribute; 1. It applies to

The formmethod attribute in HTML5 is used to specify the HTTP method (such as get or post) that should be used when submitting a form from a button or input element. It overrides the method defined in the <form></form> element’s method attribute, but only for that specific button's submission.

This attribute is typically used with <button></button> or <input type="submit"> elements that are inside a form or associated with one.
Key Points:
-
Applies to:
<button></button>and<input type="submit"> -
Values:
getorpost(most common), though other HTTP methods likeputordeletemay be supported in specific contexts via spoofing. -
Overrides: The
methodattribute of the parent<form></form> - Use case: Allows different buttons in the same form to submit data using different methods.
Example:
<form action="/submit" method="get"> <input type="text" name="username" /> <!-- This button will use POST instead of GET --> <button type="submit" formmethod="post">Submit with POST</button> <!-- This button uses the form's default GET method --> <button type="submit">Submit with GET</button> </form>
In this example:

- Clicking the first button sends the form data via
POSTto/submit, even though the form's default method isget. - Clicking the second button uses the form’s default
GETmethod.
Common Use Cases:
- A form with both "Save Draft" (
POST) and "Preview" (GET) buttons. - Admin interfaces where one button deletes (using
postwith a hidden_methodfield simulatingdelete) and another updates (usingpost).
Notes:
- The
formmethodattribute only works on submit buttons. - It must be used in conjunction with a form (either inside it or via the
formattribute). - For
get, form data is appended to the URL; forpost, it's sent in the request body.
Basically, formmethod gives you fine-grained control over how individual buttons submit a form, without needing multiple forms or JavaScript.
The above is the detailed content of What is the formmethod attribute in HTML5?. For more information, please follow other related articles on the PHP Chinese website!
Hot AI Tools
Undress AI Tool
Undress images for free
AI Clothes Remover
Online AI tool for removing clothes from photos.
Undresser.AI Undress
AI-powered app for creating realistic nude photos
ArtGPT
AI image generator for creative art from text prompts.
Stock Market GPT
AI powered investment research for smarter decisions
Hot Article
Popular tool
Notepad++7.3.1
Easy-to-use and free code editor
SublimeText3 Chinese version
Chinese version, very easy to use
Zend Studio 13.0.1
Powerful PHP integrated development environment
Dreamweaver CS6
Visual web development tools
SublimeText3 Mac version
God-level code editing software (SublimeText3)
Hot Topics
20522
7
13634
4




