From 9cc9cb03385ddc7518226d170400d2cca61a219e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Tue, 14 Oct 2025 16:10:51 +0200 Subject: [PATCH] =?utf8?q?Set=20captcha=20=C3=A0=20required=20Add=20not=20?= =?utf8?q?about=20error=20bubbling=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Form/CaptchaType.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Form/CaptchaType.php b/Form/CaptchaType.php index 8b0a872..9d9db16 100644 --- a/Form/CaptchaType.php +++ b/Form/CaptchaType.php @@ -57,7 +57,7 @@ class CaptchaType extends AbstractType { $builder->add('_captcha_token', HiddenType::class, ['data' => $captcha['token'], 'empty_data' => $captcha['token'], 'mapped' => false]); //Add captcha - $builder->add('captcha', IntegerType::class, ['label_attr' => ['class' => 'captcha'], 'label' => ''.htmlentities($captcha['equation']).'', 'label_html' => true, 'mapped' => false, 'translation_domain' => false]); + $builder->add('captcha', IntegerType::class, ['label_attr' => ['class' => 'captcha'], 'label' => ''.htmlentities($captcha['equation']).'', 'label_html' => true, 'mapped' => false, 'translation_domain' => false, 'required' => true]); //Add event listener on captcha $builder->addEventListener(FormEvents::PRE_SUBMIT, [$this, 'validateCaptcha']); @@ -96,6 +96,8 @@ class CaptchaType extends AbstractType { //Without captcha if (empty($data['captcha'])) { //Add error on captcha + //XXX: we need to add error on form + //XXX: see https://github.com/symfony/symfony/issues/35831 $form->addError(new FormError($this->translator->trans('Captcha is empty'))); //Reset captcha token @@ -106,6 +108,8 @@ class CaptchaType extends AbstractType { //With invalid captcha } elseif ($this->slugger->hash($data['captcha']) !== $data['_captcha_token']) { //Add error on captcha + //XXX: we need to add error on form + //XXX: see https://github.com/symfony/symfony/issues/35831 $form->addError(new FormError($this->translator->trans('Captcha is invalid'))); //Reset captcha token -- 2.41.3