0

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. Commented Dec 23, 2012 at 14:22

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.