Sometimes, we want to make a HTML button perform a POST request.
In this article, we’ll look at how to make a HTML button perform a POST request.
How to make a HTML button perform a POST request?
To make a HTML button perform a POST request, we add a name attribute to the button.
For instance, we write
<form action="" method="post">
<button name="foo" value="upvote">Upvote</button>
</form>
to set the name attribute of the button to foo.
Then when we press it, it’ll perform a post request.
We set the method attribute to post so that it performs the post request when we click it.
Conclusion
To make a HTML button perform a POST request, we add a name attribute to the button.