diff --git a/src/Form/Handler/ContactFormHandler.php b/src/Form/Handler/ContactFormHandler.php index f2b53c77..d594e5bd 100644 --- a/src/Form/Handler/ContactFormHandler.php +++ b/src/Form/Handler/ContactFormHandler.php @@ -40,15 +40,24 @@ public function handle(FormInterface $form, Request $request): bool /** @var ContactSubmission $data */ $data = $form->getData(); - - $result = $this->recaptcha->validateRecaptchaToken($data->getRecaptchaToken()); + $captchaResult = $this->recaptcha->validateRecaptchaToken($data->getRecaptchaToken()); // Client succeed recaptcha validation. - if ($result['success'] && $this->mailer->sendContactFormEmail($data)) { - $this->translator->setLocale($request->getLocale()); - $this->session->getFlashBag()->add('success', $this->translator->trans('flashes.contact.success')); + if ($captchaResult['success'] !== true) { + $this->session->getFlashBag()->add('danger', 'You seem like a robot, sorry.'); + return false; } + $mailResult = $this->mailer->sendContactFormEmail($data); + + if (!$mailResult) { + $this->session->getFlashBag()->add('danger', 'Mail was not sent due to unknown error.'); + return false; + } + + $this->translator->setLocale($request->getLocale()); + $this->session->getFlashBag()->add('success', $this->translator->trans('flashes.contact.success')); + return true; } } diff --git a/src/Service/RecaptchaService.php b/src/Service/RecaptchaService.php index ba2b6927..5a04046a 100644 --- a/src/Service/RecaptchaService.php +++ b/src/Service/RecaptchaService.php @@ -21,7 +21,7 @@ public function validateRecaptchaToken(string $token): array $resp = $recaptcha ->setExpectedHostname($_SERVER['SERVER_NAME']) ->setExpectedAction($this->recaptchaSecret->action) - ->setScoreThreshold($this->recaptchaSecret->treshold) + ->setScoreThreshold($this->recaptchaSecret->threshold) ->verify($token, $_SERVER['REMOTE_ADDR']); return $resp->toArray(); diff --git a/templates/base.html.twig b/templates/base.html.twig index cc1ef490..a7dbc67e 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -53,8 +53,6 @@ style="display:none;visibility:hidden"> - {% block headScripts %} {% endblock headScripts %} - {% endif %} +{% block headScripts %} {% endblock headScripts %}