👀 Live Preview
Two submit buttons in one form, each using a different HTTP method:

The formmethod attribute is a useful HTML feature that lets developers specify the HTTP method used when submitting a form. Applied to <button> or <input type="submit"> elements, it overrides the method on the parent <form> for that one submission.
Per-button HTTP verb.
Data in URL params.
Data in body.
button and input.
JS property name.
One form, two methods.
formmethodThe formmethod attribute is designed to give developers control over the HTTP method used to submit a form on a per-button basis. This is particularly useful when you have multiple submit buttons in a form and want each to trigger a different type of request.
For example, a single form might offer “Preview” via GET (data visible in the URL for a read-only view) and “Save” via POST (data sent securely in the request body).
get appends name-value pairs to the URL—good for searches and idempotent reads. post sends data in the body—use for creating, updating, or sensitive data.
Add formmethod to a submit button with either get or post:
<form action="/submit" method="post">
<input type="text" name="data">
<button type="submit" formmethod="get">Submit with GET</button>
<button type="submit" formmethod="post">Submit with POST</button>
</form><button type="submit">, <input type="submit">, and <input type="image">.get and post (case-insensitive in HTML).method only for that button’s submission.formaction and formenctype for full per-button submission control.The formmethod attribute accepts the following values:
get — Submits form data as URL query parameters. Generally used for retrieving or filtering data. Bookmarkable and cacheable.post — Submits form data in the HTTP request body. Commonly used for data that should not appear in the URL, such as passwords or large payloads.<!-- GET: /search?q=html -->
<button type="submit" formmethod="get">Search</button>
<!-- POST: data in request body -->
<button type="submit" formmethod="post">Save</button>| Item | Details | Notes |
|---|---|---|
| Attribute on | Submit buttons | Not on <form> itself |
| Values | get, post | Case-insensitive |
| GET behavior | Data in URL query string | Limited length; visible in address bar |
| POST behavior | Data in request body | Better for sensitive or large data |
| JS property | button.formMethod | CamelCase in JavaScript |
| Default | Form method | Usually get if omitted |
| Element | Supported? | Notes |
|---|---|---|
<button type="submit"> | Yes | Semantic submit buttons |
<input type="submit"> | Yes | Classic submit inputs |
<input type="image"> | Yes | Image-based submit control |
<form> | No | Forms use method; buttons use formmethod |
<input type="text"> | No | Not a submit control |
method vs formmethod| Attribute | On | Behavior |
|---|---|---|
method | <form> | Default HTTP method for all submit buttons |
formmethod | Submit button / input | Overrides method for that button only |
| Method | Data Location | Best For |
|---|---|---|
get | URL query string | Search, filters, read-only previews |
post | Request body | Login, create/update, file uploads |
GET and POST buttons in one form, a preview-vs-save pattern, and dynamic formMethod with JavaScript.
Two submit buttons in one form, each using a different HTTP method:
Here’s a simple example demonstrating how to use the formmethod attribute in an HTML form:
<form action="/submit" method="post">
<label for="data">Enter Data:</label>
<input type="text" id="data" name="data">
<button type="submit" formmethod="get">Submit with GET</button>
<button type="submit" formmethod="post">Submit with POST</button>
</form>Clicking “Submit with GET” submits the form using the GET method. Clicking “Submit with POST” uses POST, regardless of the method="post" on the form tag (the GET button overrides it).
A practical pattern: preview with GET, save with POST:
<form action="/articles" method="post">
<textarea name="body" required></textarea>
<button type="submit" formmethod="get" formaction="/articles/preview">Preview</button>
<button type="submit">Save</button>
</form>“Preview” sends a GET request to /articles/preview so the user can see a read-only view. “Save” uses the form’s default POST method to persist the article.
You can dynamically set the formmethod attribute using JavaScript to change the submission method based on user interaction:
<form action="/submit" method="post" id="dynamicForm">
<label for="dynamicData">Enter Data:</label>
<input type="text" id="dynamicData" name="dynamicData">
<button type="button" onclick="setFormMethod('get')">Set Method to GET</button>
<button type="button" onclick="setFormMethod('post')">Set Method to POST</button>
<button type="submit" id="submitButton">Submit</button>
</form>
<script>
function setFormMethod(method) {
document.getElementById("submitButton").formMethod = method;
}
</script>Clicking “Set Method to GET” assigns formMethod = "get" on the submit button. Clicking “Set Method to POST” sets it to post. The submit button then uses the dynamically chosen method.
Usually GET or POST on the form element.
Submit control picks GET or POST.
Data goes in URL (GET) or body (POST).
One form, multiple HTTP methods without duplicating fields.
The formmethod attribute is supported in all modern browsers. It is part of the HTML5 form submission override attributes alongside formaction and formenctype.
All major browsers honor formmethod on submit controls.
Bottom line: Use formmethod confidently; ensure your server handles both GET and POST if you offer both.
formmethod to control submission methods for different buttons in the same formformaction when URL and method should both differformMethod (camelCase) in JavaScriptformmethod on non-submit controlsThe formmethod attribute is a powerful tool for managing form submission behaviors in HTML. By using this attribute, you can specify different HTTP methods for form submissions on a per-button basis, enhancing the flexibility and functionality of your forms.
Dynamic control with JavaScript via formMethod adds further customization. Always label buttons clearly and handle both GET and POST correctly on the server.
formmethodBookmark these before adding multi-method forms.
Per submit button.
PurposeData in URL.
ValueData in body.
ValueJS property name.
ScriptUse POST for sensitive data.
Securitymethod attribute for the submit button that was clicked, using GET or POST for that submission.get and post. These are the only valid values for formmethod on submit controls.<button type="submit">, <input type="submit">, and <input type="image">.method is on the <form> as the default. formmethod on a submit button overrides it for that button only.buttonElement.formMethod = "get" or setAttribute("formmethod", "post"). Note the camelCase property name in JavaScript.Practice overriding HTTP methods with formmethod in the Try It editor.
3 people found this page helpful