From 4fde3289cc0881cd23629335c29cf5f54be242bc Mon Sep 17 00:00:00 2001 From: Stephan Strate Date: Thu, 14 Jan 2021 12:39:38 +0100 Subject: [PATCH 01/15] do not execute form action captcha, ip and timestamp if value is false --- form.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/form.php b/form.php index bae80f94..a581d9d8 100644 --- a/form.php +++ b/form.php @@ -414,6 +414,9 @@ public function onFormProcessed(Event $event): void switch ($action) { case 'captcha': + if (Utils::isNegative($params)) { + break; + } $captcha_config = $this->config->get('plugins.form.recaptcha'); @@ -475,6 +478,10 @@ public function onFormProcessed(Event $event): void } break; case 'timestamp': + if (Utils::isNegative($params)) { + break; + } + $label = $params['label'] ?? 'Timestamp'; $format = $params['format'] ?? 'Y-m-d H:i:s'; $blueprint = $form->value()->blueprints(); @@ -485,6 +492,10 @@ public function onFormProcessed(Event $event): void $form->setData('timestamp', $date_string); break; case 'ip': + if (Utils::isNegative($params)) { + break; + } + $label = $params['label'] ?? 'User IP'; $blueprint = $form->value()->blueprints(); $blueprint->set('form/fields/ip', ['name' => 'ip', 'label' => $label, 'type' => 'hidden']); From 18f3674ed7f3a0e9dc65432dec37eecb6f519865 Mon Sep 17 00:00:00 2001 From: Stephan Strate Date: Thu, 14 Jan 2021 19:12:15 +0100 Subject: [PATCH 02/15] add negative check before executing action --- classes/Form.php | 5 +++++ form.php | 12 ------------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/classes/Form.php b/classes/Form.php index dad2974b..e917ad2f 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -915,6 +915,11 @@ public function post() $data = $data[$action]; } + // do not execute action, if deactivated + if (Utils::isNegative($data)) { + continue; + } + $event = new Event(['form' => $this, 'action' => $action, 'params' => $data]); $grav->fireEvent('onFormProcessed', $event); diff --git a/form.php b/form.php index a581d9d8..821b891d 100644 --- a/form.php +++ b/form.php @@ -414,10 +414,6 @@ public function onFormProcessed(Event $event): void switch ($action) { case 'captcha': - if (Utils::isNegative($params)) { - break; - } - $captcha_config = $this->config->get('plugins.form.recaptcha'); $secret = $params['recaptcha_secret'] ?? $params['recatpcha_secret'] ?? $captcha_config['secret_key']; @@ -478,10 +474,6 @@ public function onFormProcessed(Event $event): void } break; case 'timestamp': - if (Utils::isNegative($params)) { - break; - } - $label = $params['label'] ?? 'Timestamp'; $format = $params['format'] ?? 'Y-m-d H:i:s'; $blueprint = $form->value()->blueprints(); @@ -492,10 +484,6 @@ public function onFormProcessed(Event $event): void $form->setData('timestamp', $date_string); break; case 'ip': - if (Utils::isNegative($params)) { - break; - } - $label = $params['label'] ?? 'User IP'; $blueprint = $form->value()->blueprints(); $blueprint->set('form/fields/ip', ['name' => 'ip', 'label' => $label, 'type' => 'hidden']); From 3e5f6b12cb0428f212ad35569939d4f9940a4fa4 Mon Sep 17 00:00:00 2001 From: Stephan Strate Date: Fri, 15 Jan 2021 09:24:29 +0100 Subject: [PATCH 03/15] do not execute only if 'false' --- classes/Form.php | 2 +- form.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/Form.php b/classes/Form.php index e917ad2f..c4e8065e 100644 --- a/classes/Form.php +++ b/classes/Form.php @@ -916,7 +916,7 @@ public function post() } // do not execute action, if deactivated - if (Utils::isNegative($data)) { + if (in_array($data, [false, 'false'], true)) { continue; } diff --git a/form.php b/form.php index 821b891d..bae80f94 100644 --- a/form.php +++ b/form.php @@ -414,6 +414,7 @@ public function onFormProcessed(Event $event): void switch ($action) { case 'captcha': + $captcha_config = $this->config->get('plugins.form.recaptcha'); $secret = $params['recaptcha_secret'] ?? $params['recatpcha_secret'] ?? $captcha_config['secret_key']; From da681d2e6b71c947392984c6f1b1afdf4685dc1b Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 9 Feb 2021 15:03:34 -0800 Subject: [PATCH 04/15] Fixed form link to learn --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d171e9e0..627c9876 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ enabled: true # How to use the Form Plugin The Learn site has two pages describing how to use the Form Plugin: -- [Forms](http://learn.getgrav.org/advanced/forms) +- [Forms](https://learn.getgrav.org/forms) - [Add a contact form](http://learn.getgrav.org/forms/forms/example-form) # Using email From a0500edc3344e12def8754e4fa96aa76c065cbe5 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 9 Feb 2021 21:32:32 -0800 Subject: [PATCH 05/15] Fixed reCaptcha v3 incompatibility with multiple forms on the same page sharing different actions (fixes #416) --- CHANGELOG.md | 6 ++++++ templates/forms/fields/captcha/captcha.html.twig | 16 ++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16878729..2f41a2fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v4.3.2 +## mm/dd/2021 + +1. [](#bugfix) + * Fixed reCaptcha v3 incompatibility with multiple forms on the same page sharing different actions [#416](https://github.com/getgrav/grav-plugin-form/issues/416) + # v4.3.1 ## 01/31/2021 diff --git a/templates/forms/fields/captcha/captcha.html.twig b/templates/forms/fields/captcha/captcha.html.twig index f9a654a9..07ce494a 100644 --- a/templates/forms/fields/captcha/captcha.html.twig +++ b/templates/forms/fields/captcha/captcha.html.twig @@ -15,11 +15,13 @@ {% do assets.addJs('https://www.google.com/recaptcha/api.js?render='~site_key~'&theme=' ~ theme) %} {##} {% elseif config.plugins.form.recaptcha.version == '2-invisible' %}