Skip to content

Commit

Permalink
Added errorJavascriptDisabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Feb 16, 2021
1 parent b9de54e commit 7ede821
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Snaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function validateField(ActionEvent $event)
$variables = [
'errorTitle' => $this->settings->errorTitle,
'errorMessage' => $this->settings->errorMessage,
'errorJavascriptDisabled' => $this->settings->errorJavascriptDisabled,
'errorButtonText' => $this->settings->errorButtonText,
'postedValues' => Craft::$app->request->getBodyParams(),
];
Expand Down
5 changes: 4 additions & 1 deletion src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
//'fieldName' => 'snaptcha',

// The error message that will be displayed if Snaptcha identifies a submission as spam.
//'errorMessage' => 'Sorry, you have failed the security test. Please ensure that you have javascript enabled and that, you refresh the page that you are trying to submit.'
//'errorMessage' => 'For some reason your submission was flagged as spam. Please click the button below to resubmit your data.'

// The error that will be displayed if Snaptcha identifies a submission as spam and JavaScript is disabled.
//'errorJavascriptDisabled' => 'JavaScript must be enabled for your submission to be verified. Please enable it and refresh the page.'

// The text that will be displayed in the button if Snaptcha identifies a submission as spam.
//'errorButtonText' => 'Click this button to resubmit the form.',
Expand Down
7 changes: 6 additions & 1 deletion src/models/SettingsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class SettingsModel extends Model
/**
* @var string
*/
public $errorMessage = 'For some reason your submission was flagged as spam. Please ensure that you have JavaScript enabled and click the button below to resubmit your data.';
public $errorMessage = 'For some reason your submission was flagged as spam. Please click the button below to resubmit your data.';

/**
* @var string
*/
public $errorJavascriptDisabled = 'JavaScript must be enabled for your submission to be verified. Please enable it and refresh the page.';

/**
* @var string
Expand Down
15 changes: 13 additions & 2 deletions src/templates/_error.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

{% set title = errorTitle %}

{% js %}
document.getElementById('warning').remove();
document.getElementById('error').classList.remove('hidden');
document.getElementById('resubmit').classList.remove('disabled');
{% endjs %}

{% block message %}

<h2>{{ errorTitle }}</h2>

<p>{{ errorMessage }}</p>
<p id="error" class="hidden">
{{ errorMessage }}
</p>

<p id="warning" class="warning">
{{ errorJavascriptDisabled }}
</p>

<form action="" method="post">
{% for name, value in postedValues %}
Expand All @@ -16,7 +27,7 @@ <h2>{{ errorTitle }}</h2>

{{ craft.snaptcha.field }}

<button type="submit" class="btn submit" style="font-weight: bold; text-transform: uppercase;">
<button id="resubmit" type="submit" class="btn submit disabled" style="font-weight: bold; text-transform: uppercase;">
{{ errorButtonText }}
</button>
</form>
Expand Down
10 changes: 10 additions & 0 deletions src/templates/_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
errors: settings.getErrors('errorMessage')
}) }}

{{ forms.textField({
required: true,
label: 'Error JavaScript Disabled'|t('snaptcha'),
name: 'errorJavascriptDisabled',
instructions: 'The error that will be displayed if Snaptcha identifies a submission as spam and JavaScript is disabled.'|t('snaptcha'),
warning: (config.errorMessage is defined ? configWarning('errorJavascriptDisabled')),
value: settings.errorJavascriptDisabled,
errors: settings.getErrors('errorJavascriptDisabled')
}) }}

{{ forms.textField({
required: true,
label: 'Error Button Text'|t('snaptcha'),
Expand Down

0 comments on commit 7ede821

Please sign in to comment.