CaptchaBundle icon indicating copy to clipboard operation
CaptchaBundle copied to clipboard

Question: How can I specify a validation group?

Open kieste opened this issue 10 years ago • 2 comments

I want to specify the validation group in which the capture must be validated. Usualy I do this via a constraint. How can I do this using the captcha?

kieste avatar Mar 26 '14 23:03 kieste

I think you will have to tap into overriding the form type and setting dynamically this groups as options perhaps. If you are over the problem please close thanks

cordoval avatar May 13 '15 01:05 cordoval

This is my workaround:

<?php

use Gregwar\CaptchaBundle\Type\CaptchaType as BaseCaptchaType;

class CaptchaType extends BaseCaptchaType
{
    public function __construct(SessionInterface $session, CaptchaGenerator $generator, TranslatorInterface $translator, $options)
    {
        $options['disable_validation'] = false;

        parent::__construct($session, $generator, $translator, $options);
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['disable_validation']) {
            return;
        }

        parent::buildForm($builder, $options);
    }
}

When I want to disable validaiton, I just use:

->add('captcha', CaptchaType::class, [
    'disable_validation' => true,
])

umpirsky avatar Jun 29 '17 17:06 umpirsky