customer validator and multiple errors

Hello,

I have a custom validator, where I am validating two input fields. These two input fields are dependent of each other, a time start field and a time end field. When both are filled out I need to validate if there are any time intervals conflicting with the chosen. If there are such intervals, I would like to add an error both input fields, but this obviously doesn’t work:




...

$this->addError($object, 'time_start', $error);

$this->addError($object, 'time_end', $error);

...



Does anyone have experiences with this sort of problem?

Regards Mads

I recommend you to write your own validator or use a custom one (check the authenticate custom validation for example: http://www.yiiframework.com/doc/guide/1.1/en/form.model#declaring-validation-rules)

Hi Antonio,

Thanks for your reply.

My own validator is exactly what I’m doing. In this validator I would like to add more than one error at a time. I.e. I would like to do something like




...

if($error)

{

$this->addError($object, 'time_start', $error);

$this->addError($object, 'time_end', $error);

}

...



The reason is that I must validate if a time interval is legal or not. An illegal time interval interferes with other registered time intervals. For instance if there is a registered time interval, say 9.00-10.00 and a user types in the interval 8.00-11.00 this is illegal as it overlaps. But I don’t know if it’s 8.00, 11.00 or both that is wrong. Therefore I would like to mark both as having error. Because if I in my validator choose to say 11.00 is wrong and the user changes 8.00 to 10.30, then this interval is not longer illegal, but the validator won’t register this case as legal.

Hope I’m a little more clear.

Regards Mads

Never mind this. I rethought the porblem and found a simpler solution to it.