Answer the question
In order to leave comments, you need to log in
How to dynamically add validation rules in Yii2?
I am using Active Form. Some form fields are taken from the database. Their type, name and validation rules are stored there. The fields are different and have different characteristics. How to set validation rules for these fields? So that the framework understands them, both on the server side and on the client side.
Stayed to use DynamicModel . But the class needs to pass an attribute with the field value. Means approaches only for server validation. What about the client?
Answer the question
In order to leave comments, you need to log in
With client validation, you need to add js code
www.yiiframework.com/doc-2.0/guide-input-validatio...
in models, you can assign rules for scenarios
use DynamicModel for this
$model = DynamicModel::validateData(compact('name', 'email'), [
[['name', 'email'], 'string', 'max' => 128],
['email', 'email'],
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question