Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

method — form submission method

The method attribute on form selects get, post, or dialog. It determines how form data is submitted, or closes a dialog instead of making a network request.

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

Syntax

<form method="get|post|dialog">…</form>

The method attribute on form selects how form submission is handled. Its allowed values are get, post, and dialog. Omitting the attribute or supplying an invalid value, including an empty string or put, selects the GET state.

For HTTP(S) destinations, get places encoded form data in the URL query, whereas post sends it in the request body. The action attribute specifies the destination; enctype specifies the body encoding for post.

The dialog value closes the nearest ancestor dialog without sending data over the network. Without such an ancestor, submission does not proceed. Validation can still block this operation. In the example, the button sets the dialog's returnValue to ok.

A formmethod attribute on the submit button used overrides the form's method. If absent, the form's setting applies; an invalid formmethod selects GET rather than inheriting the setting.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>method demo</title>
<dialog id="choice">
  <form method="dialog">
    <button type="submit" value="ok">OK</button>
  </form>
</dialog>
<pre id="result">waiting</pre>
<script>
  const choice = document.getElementById('choice');
  const result = document.getElementById('result');
  choice.addEventListener('close', () => {
    result.textContent = `returnValue=${choice.returnValue}`;
  });
  choice.showModal();
</script>
</html>

Result

returnValue=ok

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