I have one form which has multiple inputs with same name which are dynamically added using jQuery. Input names are as below:
ModelName[dynamic_name][]
ModelName[dynamic_name][]
I have also declared dynamic_name
as public variable in a Model
. How can I validate the above inputs using yii2 validation rule?
yii2, you can use with
Class yii\validators\EachValidator
VIEW
MODEL
Link: http://www.yiiframework.com/doc-2.0/yii-validators-eachvalidator.html
Since your
dynamic_name
variable will be an array of input values, you can use the neweach
validator. It was added in v2.0.4. It takes an array and passes each element into another validator.For example, to check if each element is an integer: