This content originally appeared on Go Make Things and was authored by Go Make Things
Last week, I wrote an article about progressively enhancing HTML forms with JavaScript. In the article, I originally wrote (now corrected)…
But by default, forms send a
POST
request
This was wrong. By default, forms send a GET
request to whatever URL is included as the value of the action
attribute, or the current URL if none is provided.
You can modify this default behavior with the method
attribute.
Whatever HTTP method you include as its value will be used instead. For example, his form will be sent with the POST
method instead of GET
.
<form action="path/to/the/endpoint.php" method="POST">
<label for="email">Enter your email</label>
<input type="email" id="email" name="email">
<button>Subscribe</button>
</form>
❄️ Holiday Sale! Now through the New Year, save 40% on every pocket guide, video course, and enrollment in the Vanilla JS Academy. If you buy a pocket guide bundle or join Academy, you'll also get $673 in free bonus gifts.
This content originally appeared on Go Make Things and was authored by Go Make Things
Go Make Things | Sciencx (2022-12-29T14:30:00+00:00) How to control the HTTP method forms use. Retrieved from https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.