Hey!
In order to use custom validators, first you should register your custom
validator in ValidatorManager:
$validatorManager = new ValidatorManager();
$validatorManager->setService('custom', new MyCustomValidator());
Then register your ValidatorManager in InputFilter factory:
$formFactory = new Factory();
$formFactory->getInputFilterFactory()->getDefaultValidatorChain()->setPluginManager($validatorManager);
Now it should work :)
Em qui, 28 de jul de 2016 às 04:40, Bikash Poudel <
[email protected]> escreveu:
> Hello,
>
> Was wondering if anyone has come across this problem previously.
> I am using the preconfigured form spec to create form using the
> Zend\Form\Factory, I am also injecting the FormElementManager into the
> factory so it can find my custom elements etc.
>
> My question is:
>
> Even tho any custom validators are registered with the form, they do not
> trigger isValid() method. Is there anything I need to do to get the
> isValid() triggered with creating the form with factory.
>
>
> My source looks like following:
>
> <?php
> $spec = [
> 'hydrator' => '...',
> 'fieldset' => [
> ...,
> ...,
> ...,
> ],
> 'input_filter' => [
> ...,
> ....
> ....,
> //contains my custom validator in here
> ],
> ];
> $factory = new Factory();
> $factory->setFormElementManager($formElementManager);
> $form = $factory->createForm($spec);
>
> But when I trigger:
> $form->isValid()
> It doesn't get to the isValid call in my custom validator.
>
> Thank you,
> Bikash
>
--
Daniel Gimenes
twitter.com/danizord
github.com/danizord