How to control the HTTP method forms use

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.


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to control the HTTP method forms use." Go Make Things | Sciencx - Thursday December 29, 2022, https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/
HARVARD
Go Make Things | Sciencx Thursday December 29, 2022 » How to control the HTTP method forms use., viewed ,<https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/>
VANCOUVER
Go Make Things | Sciencx - » How to control the HTTP method forms use. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/
CHICAGO
" » How to control the HTTP method forms use." Go Make Things | Sciencx - Accessed . https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/
IEEE
" » How to control the HTTP method forms use." Go Make Things | Sciencx [Online]. Available: https://www.scien.cx/2022/12/29/how-to-control-the-http-method-forms-use/. [Accessed: ]
rf:citation
» How to control the HTTP method forms use | Go Make Things | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.