Take the 2-minute tour ×

I have created a custom validation function in my model. I know each rule (and subsequently my validation function) can return one error message as is defined in the $validation array. But my function checks multiple conditions and I would like to return a more tailored and conditional model validation error message instead of a more generic one. For example, instead of displaying "You haven't passed condition A or B" as the rule message, I would like it to say "You haven passed condition A", "You haven passed condition B" or "You haven't passed condition A and B" depending on which one was breached. Is that possible? If so, how do I do that?

share|improve this question
The only way I can think of unless this works is to create one validation function for each condition. Instead of all in one function. –  alieninlondon Dec 23 '12 at 14:22

1 Answer 1

You can check those in your beforeValidate or beforeSave callback and call there

$this->invalidate('field_name1', 'error_message1');
$this->invalidate('field_name2', 'error_message2');


This way you can achieve the desired flexibility.

share|improve this answer

Your Answer


