Skip to content

Commit 405852f

Browse files
committed
Display captcha errors in LegacyTrait
1 parent ab99217 commit 405852f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

bundle/InformationCollectionLegacyTrait.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Netgen\Bundle\InformationCollectionBundle\Event\InformationCollected;
66
use Netgen\Bundle\InformationCollectionBundle\Form\Captcha\CaptchaValueInterface;
7+
use Symfony\Component\Form\FormError;
78
use Symfony\Component\HttpFoundation\Request;
89

910
trait InformationCollectionLegacyTrait
@@ -37,10 +38,11 @@ protected function collectInformation(Request $request, $locationId)
3738
->getCaptcha($location);
3839

3940
$form->handleRequest($request);
41+
$validCaptcha = $captcha->isValid($request);
42+
$formSubmitted = $form->isSubmitted();
4043

41-
if ($form->isValid() && $form->isSubmitted()) {
44+
if ($formSubmitted && $form->isValid() && $validCaptcha) {
4245
$isValid = true;
43-
4446
$event = new InformationCollected($form->getData());
4547

4648
/** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
@@ -50,6 +52,10 @@ protected function collectInformation(Request $request, $locationId)
5052
$dispatcher->dispatch(Events::INFORMATION_COLLECTED, $event);
5153
}
5254

55+
if (true === $formSubmitted && false === $validCaptcha) {
56+
$form->addError(new FormError($this->container->get('translator')->trans('form.errors.captcha_failed', array(), 'netgen_information_collection_form_messages')));
57+
}
58+
5359
return array(
5460
'is_valid' => $isValid,
5561
'form' => $form->createView(),

0 commit comments

Comments
 (0)