Hi, in my Model I need a conditional validation. Now I use the following:
$validator
->requirePresence('iban', 'create', 'update')
->notEmpty('iban')
->add('iban', [
'length' => [
'rule' => ['minlength', 22],
'message' => 'Die IBAN muss 22 Zeichen lang sein!',
]]
);
The iban needs to be 22 characters. But now I have add the condition:
Only if field ‘payer’ is set to 1, which is the field before iban.
I have tried this:
$validator->allowEmpty(‘iban’, function ($context) {
return $context[‘data’][‘payer’] === 0;
});
and receive an error: Undefinde index payer
How do I proceed?