Your model will automatically call validations before saving the data, if not then you can use the following code in your controller
In Your Controller
$this->loadModel('YourModel');
if($this->YourModel->validates())
{
$this->YourModel->save($this->data);
}
Add the code below in your model class
var $validate = array(
'first_name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.'
)
),
'last_name' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.'
)
),
'phone' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'Phone number should be valid.'
),
'phone' => array(
'rule' => array('phone', null, 'us'),
'message' => 'Phone number should be valid e.g. 555-555-5555'
)
),
'email' => array(
'email' => array(
'rule' => 'email',
'message' => 'Please enter a valid email address'
),
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank'
),
'validEmail' => array(
'rule' => array('validEmail'),
'message' => 'Email address does not exist.'
)
),
'captcha_code' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank'
)
),
'address' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.'
)
),
'city' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.'
)
),
'street' => array(
'notEmpty' => array(
'rule' => 'notEmpty',
'message' => 'This field cannot be left blank.'
)
)
);