cakephp form validation displaying default message instead of custom -


instead of custom validation message being show upon submitting form, default "this field cannot left blank" being shown. ideas?

here validation:

public $validate = array(         'id' => array(             'rule' => 'notempty'         ),         'first_name' => array(             'rule' => 'notempty'         ),         'last_name' => array(             'rule' => 'notempty'         ),         'accused_of' => array(             'rule' => 'notempty'         ),         'last_4_of_ssn' => array(             'rule' => '/^[0-9]{4}$/', // need double check             'messsage' => 'exactly 4 digits'             ),         'date_of_accusation' => array(             'rule' => array('date', 'ymd'), // need double check              'message' => 'date must in yyyy-mm-dd format.'         ),         'monitoring' => array(             'rule' => 'notempty'         )     ); 

and here form:

echo $this->form->create('offender'); echo $this->form->input('first_name', array('label' => 'first name:')); echo $this->form->input('last_name', array('label' => 'last name:')); echo $this->form->input('accused_of', array('label' => 'accused of:')); echo $this->form->input('monitoring', array('label' => 'monitoring (enter comma seperated list. ex: bac, location):')); echo $this->form->input('last_4_of_ssn', array('label' => 'last 4 digits of ssn:') ); echo $this->form->input('date_of_accusation', array('label' => 'date of accusation:')); echo $this->form->end('save new offender'); 

it appears fields have not set custom messages please go url http://book.cakephp.org/2.0/en/models/data-validation.html

you can create custom validation purpose in validation array this

   'last_4_of_ssn' => array(         'rule' => array('digitvalidate'),          'messsage' => 'exactly 4 digits'         ) 

and in model can create public function same name.

public function digitvalidate() {      $pattern = '/^[0-9]{4}$/';     if (!preg_match($pattern,$this->data['last_4_of_ssn'])) {       return false;    }    return true;  } 

i hope you.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

jquery - Keeping Kendo Datepicker in min/max range -