5
I recently upgraded my Cakephp project to version 2.4.5.
Since then, some of my forms have been with the input hidden _method
set to PUT automatically. The only way around this is by setting the 'type' => 'POST'
.
However, this was not needed in the old days. I don’t know if I’m doing something wrong, or if it’s a BUG.
This is the form
<?php echo $this->Form->create('User', array('url' => array('action' => 'new_password', $this->request->data['User']['forget_password'], 'admin' => false), 'autocomplete' => 'off')) ?>
<?php echo $this->Form->hidden('User.id') ?>
<fieldset>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<?php echo $this->Form->password('User.password', array('label' => false, 'div' => false, 'class' => 'form-control', 'placeholder' => 'Digite a nova senha')) ?>
<i class="icon-user"></i>
</span>
</label>
<label class="block clearfix">
<span class="block input-icon input-icon-right">
<?php echo $this->Form->password('User.password_confirmation', array('label' => false, 'div' => false, 'class' => 'form-control', 'placeholder' => 'Digite novamente a nova senha')) ?>
<i class="icon-user"></i>
</span>
</label>
<div class="space"></div>
<div class="clearfix">
<?php echo $this->Form->button('<i class="icon-key"></i> '. __('Enviar'), array('class' => 'width-35 pull-right btn btn-sm btn-success', 'escape' => false)) ?>
</div>
<div class="space-4"></div>
</fieldset>
<?php echo $this->Form->end() ?>
And that’s the action:
/**
* new_password method
*
* @access public
* @param String $forget_password
* @return void
* @since 1.0
* @version 1.0
* @author Patrick Maciel
*/
public function new_password($forget_password)
{
$user = $this->User->findByForgetPassword($forget_password);
if ($user == false) {
$this->Session->setFlash(__('Link inválido'), 'flash/frontend/error');
$this->redirect('/');
}
$this->layout = 'login';
if ($this->request->is('post')) {
$this->User->set = $this->request->data;
if ($this->User->validates(array('fieldList' => array('id', 'forget_password', 'password', 'password_confirmation')))) {
// ...
} else {
// ...
}
}
$user['User']['password'] = null;
$this->request->data = $user;
}
Note: I did not set the *type of the above form, just to test whether the same would occur, and the occurred.*
The action (and route) of the form page is the same as the target?
– bfavaretto
@bfavaretto Yes. As shown above.
– Patrick Maciel
I was suspicious of the standard REST routes, ms it seems that’s not it...
– bfavaretto
@bfavaretto I believe that’s it, but I still don’t understand how Cakephp treats it. See my answer.
– Patrick Maciel