Sometimes, we want to make an HTML button perform a POST request.
In this article, we’ll look at how to make an HTML button perform a POST request.
How to make an HTML button perform a POST request?
To make an HTML button perform a POST request, we add the name and value attributes to the button.
For instance, we write
<form action="" method="post">
<button name="foo" value="upvote">Upvote</button>
</form>
to add the name and value attributes to the button.
Then when we click the button, a post request is made with the name and value included.
Conclusion
To make an HTML button perform a POST request, we add the name and value attributes to the button.