php - Cakephp Not validating data in Form -


i trying validate data form(.ctp file) in cakephp 2.3.8.

echo $this->form->create('user').'<br />'.                              $this->form->input('handle', array(                                                 'rule' => 'notempty',                                                  'alphanumeric' => array(                                                      'rule'      => 'alphanumeric',                                                     'required'  => true,                                                     'message'   => 'username must letters , numbers, no special characters'                                                 ),                                                     'between' => array(                                                         'rule'      => array('between', 4, 8),                                                         'message'   => 'username must between 4 , 8 characters',                                                     ),                                                                 'isunique' => array(                                                                     'rule'      => 'isunique',                                                                     'message'   => 'this username taken. please choose different one.'                                                                 ))).'<br />'.                               $this->form->input('email',array(                                                 'type'=>'text',                                                 'placeholder'=>'enter e-mail',                                                 'class'=>'form-control')).'<br />'.                               $this->form->input('password',array(                                                 'type'=>'password',                                                 'placeholder'=>'enter password',                                                 'class'=>'form-control'));?> 

this modle code

public function beforesave($options = array()) {         parent::beforesave($options = array());         if (isset($this->data['user']['password'])) {             $this->data['user']['password'] = authcomponent::password($this->data['user']['password']);         }         $this->data['user']['token'] = security::hash(mt_rand(),'md5',true);         $this->data['user']['resetkey'] = security::hash(mt_rand(),'md5',true);         return true;     } 

but when singup, not validating data , don't know mistaking

i have not seen validation rules in view before, in either model or controller. may alternate method. try moving validation code model.

class user extends appmodel {     public $validate = array(          'handle' => array(             'lengthcheck'=>array(                 'rule'=>array('between', 4, 8),                 'message'=>'the username must between 4 , 8 characters.'             ),             'isunique'=>array(                 'rule'=>'isunique',                 'message'=>'this username taken. please choose different one.'             ),             'alphanumeric' => array(                 'rule' => array('alphanumeric'),                 'message' => 'username must letters , numbers, no special characters',             ),             'notempty' => array(                 'rule' => array('notempty'),                 'message' => 'please enter username',             ),         ),         'password' => array(             'notempty' => array(                 'rule' => array('notempty'),                 'message' => 'please enter password',             ),         ),         'email' => array(             'email' => array(                 'rule' => array('email'),                 'message' => 'invalid email',             ),             'notempty' => array(                 'rule' => array('notempty'),                 'message' => 'please enter email',             ),         ),     ); 

in view

<?php echo $this->form->create('user'); echo $this->form->input('handle', array(     'placeholder'=>'enter username',     'class'=>'form-control' )); echo $this->form->input('email', array(     'placeholder'=>'enter e-mail',     'class'=>'form-control' )); echo $this->form->input('password', array(     'placeholder'=>'enter password',     'class'=>'form-control' )); ?> 

by default, recognize password field 'type' => 'password'


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -