I have this beforeSave method in my Student model which returns true or false. Instead of displaying a standard msg for all save errors in StudentsController(Your admission could not be saved. Please try again.), I want to display a different error message when beforeSave mtd of Student model returns false. How can I do that?
StudentsController
function add(){
if ($this->Student->saveAll($this->data)){
$this->Session->setFlash('Your child\'s admission has been received. We will send you an email shortly.');
}else{
$this->Session->setFlash(__('Your admission could not be saved. Please, try again.', true));
}
}
Deceze and Chapman were right. I found the solution from the DAta validation chapter of cakephp cookbook. Thanks a lot guys.
The following is the validation rule i've added:
for Student's name in Student Model:
Then in StudentsController's add function:
There was no need for me to validate the data without saving as mentioned by Chapman. So, I didn't use: