Answer the question
In order to leave comments, you need to log in
How to validate at least one field?
Hello.
There are two tables, the first table is "Categories", where there are id, cat_1, cat_2, cat_3, and the second is "Details", where id_cat, count, option.
The tables are connected and for each category I create a quantity and a property through a cycle, now everything works and everything is created, the question is how to do validation for at least one field, that is, if there is no quantity or property for all categories, then validate and show a message: " at least one category must not be empty", and if the property and quantity are specified for at least one category, then we save.
Answer the question
In order to leave comments, you need to log in
['cat1', 'required', 'when' => function($model) {
return (empty($model->cat2) and empty($model->cat3));
}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question