Validation in cakePHP is on the client side and on the server side.
Client side validation is on the js file that is in the webroot folder.
Server side validation is on the model which we are using.
Client side validation is important as it do not save the data even if the client side validaton do not work.
For client side validation
class User extends AppModel {
public $validate = array(
'login' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Letters and numbers only'
),
between' => array(
'rule' => array('
lengthBetween', 5, 15
),
'message' => 'Between 5 to 15 characters'
) ),
'password' => array(
'rule' => array('minLength', '8'),
'message' =>
'Minimum 8 characters long'
),
'email' => 'email',
'born' => array(
'rule' => 'date',
'message' => 'Enter a valid date',
'allowEmpty' => true
)
); }
here we give first the field and then the rule that are to be applied on them.
If there is an error we also display messag
0 Comment(s)