I recently updated my CakePHP project to version 2.4.5.
Since then, some of my forms have input hidden _method
set to PUT automatically. The only way around this is to set 'type' => 'POST'
.
But that was not necessary in the old days. I do not 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 type of the form above, just to test if it would occur, and it occurred.