0
votes

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?

1
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.user1469742

1 Answers

0
votes

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');

etc

This way you can achieve the desired flexibility.