Summary -

In this topic, we described about the Formmethod with detailed example.

Formmethod used to override the method attribute of the <form> element. Formmethod used to specify the HTTP method (GET, POST, PUT, DELETE) for sending form data to the action URL when the form submitted.

We can use formmethod attribute with input types submit and picture (type="submit" or type="image"). Formmethod attribute overrides the <form> method attribute. Once the form submitted, browser first checks for formmethod attribute and use the formmethod value if specified.If formmethod attribute not specified, it checks for <form> method attribute and uses the <form> method value if specified.

If both are specified, formmethod attribute value considered and <form> method attribute ignored

Syntax -

<input type="submit" value="Submit" formmethod="POST">

Example -

Below example describes about how to formmethod attribute used with submit element.
<!DOCTYPE html>
      <h2>The formmethod Attribute</h2>
      <form action="/action-page.php" method="GET">
         First name: <input type="text" name="fname">
         Last name: <input type="text" name="lname">
         <input type="submit" value="Submit">
       <input type="submit" formmethod="POST" value="Submit using POST">

Output -

First name: Last name: