Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Why is validate(compare 2 fields) not working?
Good night, I
will immediately describe the problem: I am
doing the validation of 2 fields or 1 or 2 must be filled!
[['number', 'email'], 'required', 'when' => function($model) {
if($model->email == '' && $model->number ==''){
return false;
} else {
return true;
}
}, 'enableClientValidation' => false],
Answer the question
In order to leave comments, you need to log in
That's right - when will only apply the require validator if it returns true. You have both fields empty (it's "iron" true) and you return false - the validator is not applied.
Try like this:
[['number', 'email'], 'required', 'when' => function($model) {
return ($model->email == '' && $model->number =='');
}, 'enableClientValidation' => false],
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question