Skip to content

Commit

Permalink
Merge pull request #139 from hybridinteractive/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rosskenney authored Apr 14, 2022
2 parents 45edfd5 + 5eb56c0 commit 1d8772f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ When sending confirmation option is enabled and custom subjects per form are nee
<input type="hidden" name="message[recaptchaTemplateOverride]" value="true">
```

## Overriding saving to databse on a per form basis

```
<input type="hidden" name="message[saveSubmissionOverride]" value="true">
```

## Overriding confirmation email on a per form basis

```
<input type="hidden" name="message[disableConfirmation]" value="true">
```

## Adding invisible reCAPTCHA

Before you set your config, remember to choose `invisible reCAPTCHA` while applying for keys.
Expand Down
18 changes: 15 additions & 3 deletions src/ContactFormExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ public function init()
//TODO: You could add here a submission to a spam table.
}

// Recaptcha override
$recaptchaTemplateOverride = false;
if (is_array($e->submission->message) && array_key_exists('recaptchaTemplateOverride', $e->submission->message)) {
$recaptchaTemplateOverride = filter_var($e->submission->message['recaptchaTemplateOverride'], FILTER_VALIDATE_BOOLEAN);
// ray($recaptchaTemplateOverride);
}

if ($this->settings->recaptcha && $recaptchaTemplateOverride != true) {
Expand All @@ -121,8 +121,14 @@ public function init()
}
}

// Save to DB override
$saveSubmissionOverride = false;
if (is_array($e->submission->message) && array_key_exists('saveSubmissionOverride', $e->submission->message)) {
$saveSubmissionOverride = filter_var($e->submission->message['saveSubmissionOverride'], FILTER_VALIDATE_BOOLEAN);
}

$submission = $e->submission;
if ($this->settings->enableDatabase) {
if ($this->settings->enableDatabase && $saveSubmissionOverride != true) {
$this->contactFormExtensionsService->saveSubmission($submission);
}

Expand All @@ -132,6 +138,7 @@ public function init()
$e->toEmails = explode(',', $email);
}

// Override template (Notification)
if ($this->settings->enableTemplateOverwrite) {
// First set the template mode to the Site templates
Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE);
Expand Down Expand Up @@ -161,7 +168,12 @@ public function init()
});

Event::on(Mailer::class, Mailer::EVENT_AFTER_SEND, function (SendEvent $e) {
if ($this->settings->enableConfirmationEmail) {
$disableConfirmation = false;
if (is_array($e->submission->message) && array_key_exists('disableConfirmation', $e->submission->message)) {
$disableConfirmation = filter_var($e->submission->message['disableConfirmation'], FILTER_VALIDATE_BOOLEAN);
}

if ($this->settings->enableConfirmationEmail && $disableConfirmation != true) {
// First set the template mode to the Site templates
Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE);

Expand Down

0 comments on commit 1d8772f

Please sign in to comment.