]> Raphaël G. Git Repositories - packbundle/commitdiff
Set captcha à required
authorRaphaël Gertz <git@rapsys.eu>
Tue, 14 Oct 2025 14:10:51 +0000 (16:10 +0200)
committerRaphaël Gertz <git@rapsys.eu>
Tue, 14 Oct 2025 14:10:51 +0000 (16:10 +0200)
Add not about error bubbling issue

Form/CaptchaType.php

index 8b0a872654ca6632948307ea80008540393ac539..9d9db16e5d2a09eefd1cc09109c1dbe8ec0bf9e0 100644 (file)
@@ -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' => '<img src="'.htmlentities($captcha['src']).'" alt="'.htmlentities($captcha['equation']).'" />', 'label_html' => true, 'mapped' => false, 'translation_domain' => false]);
+                       $builder->add('captcha', IntegerType::class, ['label_attr' => ['class' => 'captcha'], 'label' => '<img src="'.htmlentities($captcha['src']).'" alt="'.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