How to make an HTML button perform a POST request?

Spread the love

To make an HTML button perform a POST request, we add a name and value attribute to the button in the form.

For instance, we write

<form action="" method="post">
  <button name="foo" value="upvote">Upvote</button>
</form>

to add a button with the name and value attributes to make it submit the form.

The form’s method attribute is set to post so a post request is made.

Leave a Reply

Your email address will not be published. Required fields are marked *