The first step to data validation is creating the validation rules in the Model. To do that, use the Model::validate array in the Model definition, for example:
class User extends AppModel {
public $validate = array(
'login' => array(
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Letters and numbers only'
),
'between' => array(
'rule' => array('between', 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 the different rules have been defined for different fields and these fields will be checked for validation at the time of calling of save() function in your controller. Only After validating these, the data will get saved into the database.