Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

formmethod — submission method for a button

The formmethod attribute selects the form submission method for a particular submit button. It accepts get, post, and dialog, overriding the form's method for a submission initiated by that button.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

formmethod="get|post|dialog"

formmethod applies to submit buttons: button elements that act as submit buttons and input elements with type="submit" or type="image". A button can act as a submit button even when type is omitted; explicit type="submit" is not required. The attribute affects a submission initiated by that button without changing the form's method attribute.

get sends data in the URL, while post sends it in the HTTP request body. dialog closes the form's ancestor dialog instead of sending data; without such an ancestor, no submission takes place.

Omitting formmethod uses the associated form's method. An invalid value, including an empty string, instead selects get, not the form's method. If the form itself has no method, its default is get.

In the example, formmethod="dialog" overrides method="post". Clicking Close closes the dialog without a form request and sets its returnValue to done, the button's value.

Examples

<!doctype html>
<meta charset="utf-8">
<title>formmethod</title>
<dialog id="demo">
  <form method="post">
    <button type="submit" formmethod="dialog" value="done">Close</button>
  </form>
</dialog>
<output id="result">waiting</output>
<script>
  const demo = document.getElementById('demo');
  const result = document.getElementById('result');
  demo.addEventListener('close', () => {
    result.textContent = demo.returnValue;
  });
  demo.showModal();
</script>

Result

done

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources