From de97912dbb7e16eb617aebd30ce58b22486bcf55 Mon Sep 17 00:00:00 2001 From: Giovanni Gioffreda Date: Wed, 22 Nov 2023 11:22:58 +1300 Subject: [PATCH] Add support for plain Symfony forms By defaulting to the submitted form value this validator can be used with custom Symfony form types. This is useful for example: - when it's not possible to post to the hardcoded "cf-turnstile-response" form field - when using a third party widget (like vue-turnstile), while still performing server side validation with Symfony validators - when the data is not submitted through a standard web request --- src/Constraints/CloudflareTurnstileValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Constraints/CloudflareTurnstileValidator.php b/src/Constraints/CloudflareTurnstileValidator.php index 88a675d..f0747fd 100644 --- a/src/Constraints/CloudflareTurnstileValidator.php +++ b/src/Constraints/CloudflareTurnstileValidator.php @@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint): void { if ($this->enable) { $request = $this->requestStack->getCurrentRequest(); - $turnstileResponse = $request->request->get('cf-turnstile-response'); + $turnstileResponse = $request->request->get('cf-turnstile-response', $value); if (empty($turnstileResponse)) { $this->context->buildViolation($constraint->message)->addviolation();