Just as with a form element’s method attribute, the formmethod attribute of a submit button indicates the HTTP verb that should be used when submitting the data via that submit button. If omitted, the method attribute of the form element is used.

Syntax:

<button formmethod="get">Submit</button>

<input type="submit" value="Upload" formmethod="post" />

Elements:

Valid values for formmethod are:

  • GET; Default. Form submission performs an HTTP GET request and thus does not contain a request body. All request data is contained in the submission URL.
  • POST; Form submission performs an HTTP POST request, with form data included as part of the request body.

When “GET” is specified, the names and values of form input elements are combined into name/value pairs and appended to the submission URL as its query string. If “POST” is specified, the values are submitted as part of the request body and encoded according to the form’s enctype attribute or the submit button’s formenctype attribute.

Example

Example with formmethod attribute:

<form action="/update.php" method="post">

  <input type="hidden" name="id" value="123" />

  <p>

    <label for="username">Username:</label>

    <input type="text" id="username" name="username" value="john1" />

  </p>

  <p>

    <input type="submit" value="Check Availability" formmethod="get"

     formaction="/check-username.php" />

    <input type="submit" value="Update" formmethod="post" />

  </p>

</form>

 

›› go to examples ››