CaptchaBundle
CaptchaBundle copied to clipboard
Question: How can I specify a validation group?
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?
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
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,
])