I am using CAKEPHP 2.5 and I am validating this field:
data[Publickey][state]
Which is an html select box, my problem is that even after I do choose one item from the select box, the validation show an error message saying I have to choose one item, it acts as if I have not chosen any item.
At the model I have this validate code:
public $validate = array(
'state' => array(
'rule' => array('notEmpty'),
'required' => true,
'message' => 'Please choose one state'
),
How can I validate correctly? I mean if I choose one option from the state select box the validation detects that I choose one item and stop showing error messages?
Thanks in advance
notEmpty is a Core Validation rule. I'm quite sure it is the 'duplicate' required that is causing the error. If it is not blank, it is filled in, which is desired result of something being required.
https://book.cakephp.org/2.0/en/models/data-validation.html#Validation::notEmpty
notEmpty is deprecated, so use notBlank:
public $validate = array(
'title' => array(
'rule' => 'notBlank',
'message' => 'This field cannot be left blank'
)
);
Since you want users to choose some state, you might better validate with inList: https://book.cakephp.org/2.0/en/models/data-validation.html#Validation::inList