HTTP Method Spoofing

Last updated 20 days ago

Although we have access to all the HTTP verbs, modern browsers still only support GET and POST. With ColdBox and HTTP Method Spoofing, you can take advantage of all the HTTP verbs in your web forms.

By convention, ColdBox will look for an _method field in the FORM scope. If one exists, the value of this field is used as the HTTP method instead of the method from the execution. For instance, the following block of code would execute with the DELETE action instead of the POST action:

<form method="POST" action="#event.buildLink( 'posts/' )#">
<input type="hidden" name="_method" value="DELETE" />
<button type="submit">Delete</button>

You can manually add these _method fields yourselves, or you can take advantage of ColdBox's HTML Helper startForm() method. Just pass the method you like, we will take care of the rest:

#html.startForm( action = "", method="DELETE" )#
#html.submitButton( name = "Delete", class = "btn btn-danger" )#