tebazil
(Vasiliy Baukin)
1
Hi, I have this situation:
in validation rules, I have a rule:
[['access_key'], 'string','length'=>32],
I fill the value of access_key in beforeSave method.
I’ve looked through yii2 source code - the validate() runs before beforeSave().
The question is: why don’t I get error when I do not set access_key ?
Thanks.
Keith
(Kburton)
2
Have you specified a ‘required’ rule?
[['access_key'], 'required'],
tebazil
(Vasiliy Baukin)
3
No, I didn’t. Does this means that in the absense of ‘required’ null or converted to false values are not validated?
georaldc
(Georaldc)
4
Doesn’t length there mean max length and not minimum (sorry, haven’t used Yii 2 yet)?
Rom
(Rokorolov)
5
tebazil
(Vasiliy Baukin)
6
I found the answer in the manual:
It means empty input validation is skipped in my case.
Rom
(Rokorolov)
7
Yes, but you can always configure the skipOnEmpty property,
[[‘access_key’], ‘string’, ‘length’ => 32, ‘skipOnEmpty’ => false],