Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2 Remove Validator from ValidatorChain

Is there a way of detaching a validator from an input? e.g.

$input->getValidatorChain()
    ->attach('email_address')
    ->attach('no_record_exists');

if($isExistingUser == true) {
    $input->getValidatorChain()
        ->remove('no_record_exists');
}
like image 627
gawpertron Avatar asked Jun 11 '13 14:06

gawpertron


2 Answers

$form->getInputFilter()->remove('no_record_exists');

Form being a Zend\Form\Form object

like image 142
Adam H Avatar answered Nov 06 '22 14:11

Adam H


To disable e.g. the required-validation, you can do :

$form->getInputFilter()->get('form-field')->setRequired(false);

like image 21
Pascal Paulis Avatar answered Nov 06 '22 14:11

Pascal Paulis