From 580f941c0b0f3cf5e5ae19c7049d04aa22179452 Mon Sep 17 00:00:00 2001 From: Joachim Beck Date: Tue, 28 Feb 2023 11:37:05 +0100 Subject: [PATCH] TASK: Add Turnstile reset link to validation errors in lazyload mode --- .../Validation/Validator/TurnstileValidator.php | 2 +- Resources/Private/Form/Turnstile.html | 15 ++++++++++----- Resources/Private/Translations/de/Main.xlf | 4 ++++ .../Private/Translations/de/ValidationErrors.xlf | 8 ++++---- Resources/Private/Translations/en/Main.xlf | 3 +++ .../Private/Translations/en/ValidationErrors.xlf | 4 ++-- Resources/Private/Translations/es/Main.xlf | 4 ++++ .../Private/Translations/es/ValidationErrors.xlf | 8 ++++---- Resources/Public/JavaScript/Turnstile.js | 6 ++++++ 9 files changed, 38 insertions(+), 16 deletions(-) diff --git a/Classes/Validation/Validator/TurnstileValidator.php b/Classes/Validation/Validator/TurnstileValidator.php index a602284..909a073 100644 --- a/Classes/Validation/Validator/TurnstileValidator.php +++ b/Classes/Validation/Validator/TurnstileValidator.php @@ -41,7 +41,7 @@ class TurnstileValidator extends AbstractValidator protected function isValid($value) { if (!is_string($value) || empty($value)) { - $this->addError('We could not identify you as a human. Please try again.', 1676890456); + $this->addError('The captcha challenge failed.', 1676890456); return; } diff --git a/Resources/Private/Form/Turnstile.html b/Resources/Private/Form/Turnstile.html index 19fbf9c..ea48598 100644 --- a/Resources/Private/Form/Turnstile.html +++ b/Resources/Private/Form/Turnstile.html @@ -19,11 +19,16 @@ data-response-field-name="--{element.parentRenderable.parentRenderable.identifier}[{element.identifier}]" > - - -
{error -> f:translate(id: '{error.code}', arguments: error.arguments, package: '{element.renderingOptions.validationErrorTranslationPackage}', source: 'ValidationErrors')}
-
-
+
+ + +
{error -> f:translate(id: '{error.code}', arguments: error.arguments, package: '{element.renderingOptions.validationErrorTranslationPackage}', source: 'ValidationErrors')}
+
+
+ + {f:translate(id: 'widget.reset.btn', package: 'Tms.Cloudflare.Turnstile')} + +
diff --git a/Resources/Private/Translations/de/Main.xlf b/Resources/Private/Translations/de/Main.xlf index 4189da5..2c03e7a 100644 --- a/Resources/Private/Translations/de/Main.xlf +++ b/Resources/Private/Translations/de/Main.xlf @@ -6,6 +6,10 @@ This form is protected by Cloudflare Turnstile. Please enable JavaScript for this page to identify you as a human. Dieses Formular ist durch Cloudflare Turnstile geschützt. Bitte aktivieren Sie JavaScript, damit diese Seite Sie als Mensch erkennen kann. + + Please click here to confirm that you are not a robot. + Bitte klicken Sie hier, um zu bestätigen, dass Sie kein Roboter sind. + diff --git a/Resources/Private/Translations/de/ValidationErrors.xlf b/Resources/Private/Translations/de/ValidationErrors.xlf index f36dafd..3848848 100644 --- a/Resources/Private/Translations/de/ValidationErrors.xlf +++ b/Resources/Private/Translations/de/ValidationErrors.xlf @@ -9,12 +9,12 @@ - We could not identify you as a human. Please try again. - Wir konnten Sie nicht als Mensch identifizieren. Bitte versuchen Sie es erneut. + The captcha challenge failed. + Die Captcha-Abfrage ist fehlgeschlagen. - We could not identify you as a human. Please try again. - Wir konnten Sie nicht als Mensch identifizieren. Bitte versuchen Sie es erneut. + The captcha challenge failed. + Die Captcha-Abfrage ist fehlgeschlagen. diff --git a/Resources/Private/Translations/en/Main.xlf b/Resources/Private/Translations/en/Main.xlf index da533da..1a833e4 100644 --- a/Resources/Private/Translations/en/Main.xlf +++ b/Resources/Private/Translations/en/Main.xlf @@ -5,6 +5,9 @@ This form is protected by Cloudflare Turnstile. Please enable JavaScript for this page to identify you as a human. + + Please click here to confirm that you are not a robot. + diff --git a/Resources/Private/Translations/en/ValidationErrors.xlf b/Resources/Private/Translations/en/ValidationErrors.xlf index 88e7441..9757351 100644 --- a/Resources/Private/Translations/en/ValidationErrors.xlf +++ b/Resources/Private/Translations/en/ValidationErrors.xlf @@ -8,10 +8,10 @@ - We could not identify you as a human. Please try again. + The captcha challenge failed. - We could not identify you as a human. Please try again. + The captcha challenge failed. diff --git a/Resources/Private/Translations/es/Main.xlf b/Resources/Private/Translations/es/Main.xlf index 1e378b4..a61b255 100644 --- a/Resources/Private/Translations/es/Main.xlf +++ b/Resources/Private/Translations/es/Main.xlf @@ -6,6 +6,10 @@ This form is protected by Cloudflare Turnstile. Please enable JavaScript for this page to identify you as a human. Este formulario está protegido por Cloudflare Turnstile. Por favor, active JavaScript para que esta página le identifique como humano. + + Please click here to confirm that you are not a robot. + Haga clic aquí para confirmar que no es un robot. + diff --git a/Resources/Private/Translations/es/ValidationErrors.xlf b/Resources/Private/Translations/es/ValidationErrors.xlf index 7d6dddb..c59d6e4 100644 --- a/Resources/Private/Translations/es/ValidationErrors.xlf +++ b/Resources/Private/Translations/es/ValidationErrors.xlf @@ -9,12 +9,12 @@ - We could not identify you as a human. Please try again. - No hemos podido identificarle como humano. Por favor, inténtelo de nuevo. + The captcha challenge failed. + El desafío captcha ha fallado. - We could not identify you as a human. Please try again. - No hemos podido identificarle como humano. Por favor, inténtelo de nuevo. + The captcha challenge failed. + El desafío captcha ha fallado. diff --git a/Resources/Public/JavaScript/Turnstile.js b/Resources/Public/JavaScript/Turnstile.js index 4dff8f2..88bee3a 100644 --- a/Resources/Public/JavaScript/Turnstile.js +++ b/Resources/Public/JavaScript/Turnstile.js @@ -13,3 +13,9 @@ function cfTurnstileLazyload() { } } cfTurnstileLazyload(); + +function cfTurnstileReset(btn) { + cfTurnstileLazyload(); + btn.closest('form').dispatchEvent(new Event('input')); + btn.closest('.cf-turnstile-error').style.display = 'none'; +}