I validate password field.
$validator
->scalar('password')
->maxLength('password', 150)
->requirePresence('password', 'create')
->notEmptyString('password', __('Fill password.'), function ($context) {
return !empty($context['data']['password_fill']);
})
->add('password', [
'minLength' => [
'rule' => ['minLength', 5],
'message' => __('Min length is {0}', 5),
],
]);
How to allow not to fill in the password if the password_fill
field has the value 0
? The condition in notEmptyString
is ignored. Thank you.