Incorrect form method generated by Cakephp 2.4

Asked

Viewed 109 times

4

My problem occurs with the following code:

<?php
echo $this->Form->create(
  'Page',
  array(
    'url' => array(
      'controller' => 'pages',
      'action' => 'delete',
      $this->request->data['Page']['id'],
      'admin' => true
    ),
    'id' => 'PageDeleteForm',
    'method' => 'POST',
    'class' => 'hide'
  )
);

echo $this->Form->end();
?>

The result of this is this:

<form action="/admin/pages/delete/16" id="PageDeleteForm" method="post" class="hide" accept-charset="utf-8">
  <div style="display:none;">
    <input type="hidden" name="_method" value="PUT">
  </div>
</form>

With this, Cakephp returns to me: Method not allowed, for mine action allows only POST or DELETE.

Why the field _method is being generated with the value PUT?

  • 2

    Try to pass 'type'=> 'POST' instead of method.

  • @bfavaretto Problem solved! The question is: why he set the method as POST, and the input as PUT? But anyway, the initial problem was solved. Thank you.

1 answer

4


I’m not sure, but I believe Cakephp got confused when you passed 'method'=> 'POST' as an option.

The standard parameter, according to documentation, is type, and not method (which is the name of the generated attribute).

type Form method defaults to POST

  • Yeah, anyway, I don’t think it was a mix-up. But I’ll check it out as soon as I can.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.