excelwebzone / EWZRecaptchaBundle

This bundle provides easy reCAPTCHA form field for Symfony.
MIT License
395 stars 160 forks source link

FosUserBundle Integration #177

Open ScherlOMatic opened 7 years ago

ScherlOMatic commented 7 years ago

After spending a few hours on how to get the Recaptcha (not invisible) working on my FosUserForm here is the solution. Maybe you guys can make a readme out of it and commit to the repo cause I think I'm not the only one with this problem.

"friendsofsymfony/user-bundle": "^2.0", "excelwebzone/recaptcha-bundle": "dev-master"

If you decided to overwrite/extend the RegistrationType.php of FOS you might be confused why your form is always valid. I found the hint in the profiler, and validation was working just finde, but no error is beeing displayed.

Simple solution, add the validation constraint to the correct validation group. Here is my live example. Works with or without ajax .

->add('captcha', EWZRecaptchaType::class, [
                    'attr' => [
                        'options' => [
                            'theme' => 'light',
                            'type' => 'image',
                            'size' => 'normal',
                            'defer' => true,
                            'async' => true,
                        ]
                    ],
                    'mapped' => false,
                    'constraints' => [
                        new RecaptchaTrue(['groups' => 'Registration'])
                    ],
])
ArmRes commented 7 years ago

Also used @Recaptcha\IsTrue(groups={"Registration"}) in annotation