Using PUT method in HTML form
The following simple technique is used by a few web frameworks:
- add a hidden _method parameter to any form that is not GET or POST:
Rationale / history of why it is not possible in pure HTML: https://softwareengineering.stackexchange.com/questions/114156/why-there-are-no-put-and-delete-methods-in-html-forms
According to the HTML standard, you can not. The only valid values for the method attribute are get and post , corresponding to the GET and POST HTTP methods. is invalid HTML and will be treated like , i.e. send a GET request.
Instead, many frameworks simply use a POST parameter to tunnel the HTTP method:
Of course, this requires server-side unwrapping.
XHTML 1.x forms only support GET and POST. GET and POST are the only allowed values for the «method» attribute.
Can I use «Put» method in html form to send data from HTML Form to server?
Yes you can, but keep in mind that it will not result in a PUT but a GET request. If you use an invalid value for the method attribute of the tag, the browser will use the default value get .
HTML forms (up to HTML version 4 (, 5 Draft) and XHTML 1) only support GET and POST as HTTP request methods. A workaround for this is to tunnel other methods through POST by using a hidden form field which is read by the server and the request dispatched accordingly. XHTML 2.0 once planned to support GET, POST, PUT and DELETE for forms, but it’s going into XHTML5 of HTML5, which does not plan to support PUT. [update to]
You can alternatively offer a form, but instead of submitting it, create and fire a XMLHttpRequest using the PUT method with JavaScript.
Using PUT method in HTML form
Can I use a PUT method in an HTML form to send data from the form to a server?
Html Solutions
Solution 1 — Html
According to the https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-method»>HTML standard, you can not. The only valid values for the method attribute are get and post , corresponding to the GET and POST HTTP methods. is invalid HTML and will be treated like , i.e. send a GET request.
Instead, many frameworks simply use a POST parameter to tunnel the HTTP method:
method="post" . > type="hidden" name="_method" value="put" /> .
Of course, this requires server-side unwrapping.
Solution 2 — Html
XHTML 1.x forms only support GET and POST. GET and POST are the only allowed values for the «method» attribute.
Solution 3 — Html
> Can I use «Put» method in html form to send data from HTML Form to server?
Yes you can, but keep in mind that it will not result in a PUT but a GET request. If you use an invalid value for the method attribute of the tag, the browser will use the default value get .
> HTML forms (up to HTML version 4 (, 5 Draft) and XHTML 1) only support GET and POST as HTTP request methods. A workaround for this is to tunnel other methods through POST by using a hidden form field which is read by the server and the request dispatched accordingly. XHTML 2.0 once planned to support GET, POST, PUT and DELETE for forms, but it’s going into XHTML5 of HTML5, which does not plan to support PUT. [update to]
You can alternatively offer a form, but instead of submitting it, create and fire a XMLHttpRequest using the PUT method with JavaScript.
Solution 4 — Html
_method hidden field workaround
The following simple technique is used by a few web frameworks:
- add a hidden _method parameter to any form that is not GET or POST:
type="hidden" name="_method" value="PUT">
Solution 5 — Html
Unfortunately, modern browsers do not provide native support for HTTP PUT requests. To work around this limitation, ensure your HTML form’s method attribute is “post”, then add a method override parameter to your HTML form like this:
type="hidden" name="_METHOD" value="PUT"/>
To test your requests you can use «Postman» a google chrome extension
Solution 6 — Html
for people using laravel
Solution 7 — Html
To set methods PUT and DELETE I perform as following:
Then JS acts to perform the desired methods:
With these functions defined, I add a event listener to the buttons which make the form method request:
And for the remove button on the PUT form:
script> document.querySelectorAll( "[name=remove_data]" ).forEach( element => < var button = element; button.addEventListener( "click", deleteMethod ); script>
Beyond this, you can set postMethod function and getMethod to handle POST and GET submit methods as you like instead browser default behavior. You can do whatever you want instead use location.reload() , like show message of successful changes or successful deletion.
Solution 8 — Html
If you are using nodejs, you can install the package method-override that lets you do this using a middleware. Link to documentation: http://expressjs.com/en/resources/middleware/method-override.html
After installing this, all I had to do was the following:
var methodOverride = require('method-override') app.use(methodOverride('_method'))
Solution 9 — Html
I wrote an npm package called ‘html-form-enhancer’. By dropping it into your HTML source, it takes over submission of forms with methods aside from GET and POST , and also adds application/json serialization.
script type=module" src="html-form-enhancer.js"> script> form method="PUT"> . form>
Using PUT method in HTML form
XHTML 1.x forms only support GET and POST. GET and POST are the only allowed values for the «method» attribute.
Solution 2
According to the HTML standard, you can not. The only valid values for the method attribute are get and post , corresponding to the GET and POST HTTP methods. is invalid HTML and will be treated like , i.e. send a GET request.
Instead, many frameworks simply use a POST parameter to tunnel the HTTP method:
Of course, this requires server-side unwrapping.
Solution 3
Can I use «Put» method in html form to send data from HTML Form to server?
Yes you can, but keep in mind that it will not result in a PUT but a GET request. If you use an invalid value for the method attribute of the tag, the browser will use the default value get .
HTML forms (up to HTML version 4 (, 5 Draft) and XHTML 1) only support GET and POST as HTTP request methods. A workaround for this is to tunnel other methods through POST by using a hidden form field which is read by the server and the request dispatched accordingly. XHTML 2.0 once planned to support GET, POST, PUT and DELETE for forms, but it’s going into XHTML5 of HTML5, which does not plan to support PUT. [update to]
You can alternatively offer a form, but instead of submitting it, create and fire a XMLHttpRequest using the PUT method with JavaScript.
Solution 4
_method hidden field workaround
The following simple technique is used by a few web frameworks:
- add a hidden _method parameter to any form that is not GET or POST:
Solution 5
Unfortunately, modern browsers do not provide native support for HTTP PUT requests. To work around this limitation, ensure your HTML form’s method attribute is “post”, then add a method override parameter to your HTML form like this:
To test your requests you can use «Postman» a google chrome extension