dimanche 12 avril 2015

the first input block after a post request. cakephp

I have a little problem with a form in cakephp. When the view render the first time I can introduce info in all the inputs but after a submit if a validation fail the first input blocks, I can't introduce more info in there but in the rest I can. here is the view:



<?php
echo $this->Form->create('User');
echo $this->Form->input('phone');
echo $this->Form->input('complete_name');
echo $this->Form->input('adress');
echo $this->Form->input('state');
echo $this->Form->input('city');
echo $this->Form->input('zip_code');
echo $this->Form->button('Save', array('name' =>'save'));
echo $this->Form->end();
?>


In the controller:



public function user_info(){
if($this->request->is('post'))
{
if($this->User->save($this->request->data))
{
$this->redirect(array('controller' => 'users', 'action' => 'user_store'));
}
else
{
$this->Session->setFlash(__('problem saving'), 'flash_bad');
}
}


Validations of the model:



public $validate = array(
'complete_name' => array(
'notempty' => array(
'rule' => array('custom','/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
'message' => 'fail the name'
),
'maxlength' => array(
'rule' => array('maxlength', 45)
)
),

'adress' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'fail adress',
),
'maxlength' => array(
'rule' => array('maxlength', 60),
),
'minlength' => array(
'rule' => array('minlength', 10),
'message' => 'fail adress'
)
),

'state' => array(
'notempty' => array(
'rule' => array('custom', '/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
'message' => 'fail state'
),
'maxlength' => array(
'rule' => array('maxlength', 30)
)
),

'city' => array(
'notempty' => array(
'rule' => array('custom', '/^[a-z A-ZáéíóúÁÉÍÓÚñÑäëïöüÄËÏÖÜ]{5,}$/i'),
'message' => 'fail city'
),
'maxlength' => array(
'rule' => array('maxlength', 30)
)
),

'zip_code' => array(
'notempty' => array(
'rule' => '/^[1-9]{4,4}$/i',
'message' => 'fail zip code'
)
)
);


when a validation fail I can see the message in the view and the session flash too and I can edit everything except the phone. if I exchange lines in the view code like this:



<?php
echo $this->Form->create('User');
echo $this->Form->input('complete_name'); // change position with phone
echo $this->Form->input('phone');
echo $this->Form->input('adress');
echo $this->Form->input('state');
echo $this->Form->input('city');
echo $this->Form->input('zip_code');
echo $this->Form->button('Save', array('name' =>'save'));
echo $this->Form->end();
?>


Then I can't edit complete_name. someone know what is happening?


Aucun commentaire:

Enregistrer un commentaire