Using PUT method in HTML form

后端 未结 7 2104
情话喂你
情话喂你 2020-11-22 11:30

Can I use a PUT method in an HTML form to send data from the form to a server?

7条回答
  •  旧时难觅i
    2020-11-22 12:07

    _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:

      
      

      This can be done automatically in frameworks through the HTML creation helper method.

    • fix the actual form method to POST (

      )

    • processes _method on the server and do exactly as if that method had been sent instead of the actual POST

    You can achieve this in:

    • Rails: form_tag
    • Laravel: @method("PATCH")

    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

提交回复
热议问题