Is there any way to validate a BotDetect recaptcha in the symfony form builder?
I have the below form, which lets a user enter their email.:
$form = $this->createFormBuilder()
->add('email', EmailType::class,[
'label' => false,
'attr' => [
'style' => 'text-align:center;',
'value' => $email,
]
])
->add('captchaCode', CaptchaType::class, array(
'captchaConfig' => 'ExampleCaptcha'
))
->add('Do some shiz wif my email bruh.', SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
return $this->redirect('/unblock/'.$email);
}
The problem with this, is their documentation specifies a validation constraint in an Entity. My application does not have any entities (yet), but I would like to know if anyone has found a way to validate the captcha from the controller?
I'm fine with adding it to my entities when I create them , but I'm wondering how this would be done on an application that doesn't have any entities, or connection to a database.
I ended up using the beelabs google recaptcha bundle from packagist (If anyone is interested) at the link: https://packagist.org/packages/beelab/recaptcha2-bundle
Their documentation tells you pretty much everything you need to know about installation and setup.
The one drawback is that it still lets the form submit even though you havent clicked the I am not a robot checkbox, so you would need to validate whether it's been clicked on the PHP end.
You can use this to get the response, which is usually either a hash, or an empty field.
$recaptcha = $request->get('g-recaptcha-response', '');