From d41bd9195c8fce72ba27589c8913aa87367f64fe Mon Sep 17 00:00:00 2001 From: NiclasNorin Date: Tue, 25 Jun 2024 11:24:36 +0200 Subject: [PATCH 1/3] fix: conditional notification --- source/php/Submission.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/source/php/Submission.php b/source/php/Submission.php index 9671079b..f6a964eb 100644 --- a/source/php/Submission.php +++ b/source/php/Submission.php @@ -182,14 +182,23 @@ public function submit() foreach ($notify as $email) { $sendMail = true; if ($email['condition']) { - $conditionalFieldKey = sanitize_title($email['form_conditional_field']); - $sendMail = false; - if (array_key_exists($conditionalFieldKey, $_POST)) { - if ($_POST[$conditionalFieldKey] == $email['form_conditional_field_equals']) { - $sendMail = true; + $pattern = '/^id-\d+-/'; + $key = preg_replace($pattern, "", sanitize_title($key), 1); + $matchingValue = array_filter($_POST, function ($value, $key) use ($email, $pattern) { + if ($value != $email['form_conditional_field_equals']) { + return false; } - } + + if (!preg_replace($pattern, '', $key) == sanitize_title($email['form_conditional_field'])) { + return false; + } + + return true; + }, ARRAY_FILTER_USE_BOTH); + + $sendMail = !empty($matchingValue); } + if ($sendMail) { $this->notify($email['email'], $_POST['modularity-form-id'], $submission, $from); } From 2b36d0d8ae498dab613100f03a3f1980af61f3a4 Mon Sep 17 00:00:00 2001 From: Niclas Date: Tue, 25 Jun 2024 11:26:13 +0200 Subject: [PATCH 2/3] fix: removed unused row --- source/php/Submission.php | 1 - 1 file changed, 1 deletion(-) diff --git a/source/php/Submission.php b/source/php/Submission.php index f6a964eb..6ca9d2a1 100644 --- a/source/php/Submission.php +++ b/source/php/Submission.php @@ -183,7 +183,6 @@ public function submit() $sendMail = true; if ($email['condition']) { $pattern = '/^id-\d+-/'; - $key = preg_replace($pattern, "", sanitize_title($key), 1); $matchingValue = array_filter($_POST, function ($value, $key) use ($email, $pattern) { if ($value != $email['form_conditional_field_equals']) { return false; From ae52e1e275021f4e24d5588a08163c8fe77fdeb1 Mon Sep 17 00:00:00 2001 From: Niclas Date: Tue, 25 Jun 2024 11:48:12 +0200 Subject: [PATCH 3/3] chore: clarifying pattern usage --- source/php/Submission.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/php/Submission.php b/source/php/Submission.php index 6ca9d2a1..e373e4c4 100644 --- a/source/php/Submission.php +++ b/source/php/Submission.php @@ -178,17 +178,18 @@ public function submit() $autoReplyFrom = $siteMailFromName . ' '; // Send notifications + // Pattern for every field name is id-index-fieldName if ($notify) { foreach ($notify as $email) { $sendMail = true; if ($email['condition']) { - $pattern = '/^id-\d+-/'; - $matchingValue = array_filter($_POST, function ($value, $key) use ($email, $pattern) { + $fieldNamePattern = '/^id-\d+-/'; + $matchingValue = array_filter($_POST, function ($value, $key) use ($email, $fieldNamePattern) { if ($value != $email['form_conditional_field_equals']) { return false; } - if (!preg_replace($pattern, '', $key) == sanitize_title($email['form_conditional_field'])) { + if (!preg_replace($fieldNamePattern, '', $key) == sanitize_title($email['form_conditional_field'])) { return false; }