Skip to content

Commit

Permalink
Added setTimeout with settings.minimumSubmitTime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Feb 17, 2021
1 parent 385311a commit 4bd4828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/Snaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ public function validateField(ActionEvent $event)

if ($this->validated === false) {
$variables = [
'errorTitle' => $this->settings->errorTitle,
'errorMessage' => $this->settings->errorMessage,
'errorJavascriptDisabled' => $this->settings->errorJavascriptDisabled,
'errorButtonText' => $this->settings->errorButtonText,
'settings' => $this->settings,
'postedValues' => Craft::$app->request->getBodyParams(),
];

Expand Down
16 changes: 10 additions & 6 deletions src/templates/_error.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{% extends '_layouts/message' %}

{% set title = errorTitle %}
{% set title = settings.errorTitle %}

{% js %}
document.getElementById('warning').remove();
document.getElementById('error').classList.remove('hidden');
document.getElementById('resubmit').classList.remove('disabled');
setTimeout(function() {
document.getElementById('graphic').remove();
document.getElementById('resubmit').classList.remove('disabled');
}, {{ (settings.minimumSubmitTime * 1000) + random(1, 100) }});
{% endjs %}

{% block message %}

<h2>{{ errorTitle }}</h2>
<h2>{{ settings.errorTitle }}</h2>

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

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

<form action="" method="post">
Expand All @@ -28,8 +31,9 @@ <h2>{{ errorTitle }}</h2>
{{ craft.snaptcha.field }}

<button id="resubmit" type="submit" class="btn submit disabled" style="font-weight: bold; text-transform: uppercase;">
{{ errorButtonText }}
{{ settings.errorButtonText }}
</button>
<div id="graphic" class="spinner"></div>
</form>

{% endblock %}

0 comments on commit 4bd4828

Please sign in to comment.