I’m not sure if the following is a bug or a feature; I recently updated CakePHP and noticed my edit forms were not working anymore.
I use the same form generating code for new items and editing items (after all, the fields are the same). Say, we have a form for a software release:
$this->Form->input('version', ['label' => 'Version']);
$this->Form->input('description', ['label' => Description']);
The $release variable is set to the string ‘Releases’ for new items and the ORM object when editing. When saving a new item the data sent as a HTTP POST request; there are some extra variables that deal with form security (e.g. _Token) but also a variable ‘_method’ with the value ‘POST’. However, when I edit a release (i.e. the $release variable has an object) the ‘_method’ variable contains ‘PUT’.
This caused my code in my edit() routine to skip because I am checking for a POST:
function edit ($id)
// save data
The question is: do I need to change all my edit() routines to check for both POST and PUT methods now (or just PUT)? Or force a POST in all my forms? I understand the subtle differences between a POST and PUT but since 99.999% of all webforms just use POST it seems a bit overkill to me to make a distinction between the two cases (add vs. edit).