Reputation: 57
[['captcha'], 'captcha', 'required'],
If I do this, it says:
Setting unknown property: yii\captcha\CaptchaValidator::0
But it works fine if I do following:
['captcha', 'captcha'],
['captcha', 'required'],
What do you think the problem is? Why can't I combine the rules?
Upvotes: 0
Views: 80
Reputation: 60
Because in Yii, rules are represented as an array like this:
['field1', 'validator1', 'valProp1'=>'valProp1Value', 'valProp2'=>'valProp2Value', ...]
so this array applies only to 1 validator but multiple fields and valProp1, valProp2 are inbuilt Validator Class properties. Some example would be:
['field1', 'email','skipOnEmpty'=>true]
which setups yii\validators\EmailValidator
on a field1
field and setups skipOnEmpty
property of email validator to true
In order to combine rules, you need to to write in format where every rule is separate per validator, something like this:
['captcha','captcha'],
['captcha','required']
Upvotes: 3