Coder Perfect

Using the HTML form’s PUT technique

Problem

Is it possible to send data from an HTML form to a server using the PUT method?

Asked by WelcomeTo

Solution #1

You can’t, according to the HTML standard. The methods get and post, which correspond to the GET and POST HTTP methods, are the only allowed values for the method attribute. form method=”put”> is incorrect HTML and will be processed as if it were a form, i.e. a GET request will be sent.

Instead, many frameworks tunnel the HTTP method using a POST parameter:

<form method="post" ...>
  <input type="hidden" name="_method" value="put" />
...

This, of course, necessitates server-side unpacking.

Answered by phihag

Solution #2

GET and POST are the sole methods supported by XHTML 1.x forms. The only valid values for the “method” attribute are GET and POST.

Answered by dqhendricks

Solution #3

Yes, but keep in mind that it will result in a GET request rather than a PUT. The browser will use the default value get if you use an invalid value for the method property of the form> tag.

You can also provide a form, but instead of submitting it, build and fire an XMLHttpRequest with JavaScript using the PUT technique.

Answered by hakre

Solution #4

Workaround for the _method hidden field

A few web frameworks employ the following simple technique:

This can be done in the following ways:

Why there are no put and delete methods in HTML forms: https://softwareengineering.stackexchange.com/questions/114156/why-there-are-no-put-and-delete-methods-in-html-forms

Answered by Ciro Santilli 新疆再教育营六四事件法轮功郝海东

Solution #5

Unfortunately, current browsers do not implement HTTP PUT queries natively. To get around this constraint, make sure the method attribute on your HTML form is “post,” then add a method override parameter to your HTML form like this:

<input type="hidden" name="_METHOD" value="PUT"/>

You can use “Postman,” a Google Chrome extension, to test your requests.

Answered by Tofeeq

Post is based on https://stackoverflow.com/questions/8054165/using-put-method-in-html-form