Skip to content
Snippets Groups Projects
Commit 29eeb2ea authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Implement a javascript solution to stop most spam submissions from non humans.

parent 322c4173
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
{# the page has no open rounds and we arent on a round page #} {# the page has no open rounds and we arent on a round page #}
<h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applications at the moment{% endblocktrans %}</h3> <h3>{% blocktrans %}Sorry this {{ page|verbose_name }} is not accepting applications at the moment{% endblocktrans %}</h3>
{% else%} {% else%}
<form class="form" action="" method="POST" enctype="multipart/form-data"> <p class="wrapper--error message-no-js">You must have Javascript enabled to use this contact form.</p>
<form class="form application-form" action="/test500/" method="POST" enctype="multipart/form-data">
{{ form.media }} {{ form.media }}
{% csrf_token %} {% csrf_token %}
...@@ -43,13 +44,14 @@ ...@@ -43,13 +44,14 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<input class="link link--button-secondary" type="submit" value="{% if page.action_text %}{{ page.action_text|safe }}{% else %}Submit{% endif %}" /> <button class="link link--button-secondary" type="submit" disabled>{% if page.action_text %}{{ page.action_text|safe }}{% else %}Submit{% endif %}</button>
</form> </form>
{% endif %} {% endif %}
</div> </div>
{% endblock %} {% endblock %}
{% block extra_js %} {% block extra_js %}
<script src="{% static 'js/apply/application-form.js' %}"></script>
<script src="{% static 'js/apply/mailgun-validator.js' %}"></script> <script src="{% static 'js/apply/mailgun-validator.js' %}"></script>
<script src="{% static 'js/apply/file-uploads.js' %}"></script> <script src="{% static 'js/apply/file-uploads.js' %}"></script>
{% if not show_all_group_fields %} {% if not show_all_group_fields %}
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h1>{{ page.title }}</h1> <h1>{{ page.title }}</h1>
{{ page.intro|richtext }} {{ page.intro|richtext }}
<p class="wrapper--error message-no-js">You must have Javascript enabled to use this contact form.</p> <p class="wrapper--error message-no-js">You must have Javascript enabled to use this contact form.</p>
<form class="form form__wagtail-form" action="#" data-pageurl="{% pageurl page %}" method="post" enctype="multipart/form-data"> <form class="form wagtail-form" action="#" data-pageurl="{% pageurl page %}" method="post" enctype="multipart/form-data">
{% csrf_token %} {% csrf_token %}
{{ form.media }} {{ form.media }}
{% for field in form %} {% for field in form %}
......
(function ($) {
'use strict';
$('.application-form').each(function () {
var $application_form = $(this);
var $application_form_button = $application_form.find('button[type="submit"]');
// Remove the "no javascript" messages
$('.message-no-js').detach();
// Wait for a mouse to move, indicating they are human.
$('body').mousemove(function () {
// Unlock the form.
$application_form.attr('action', '');
$application_form_button.attr('disabled', false);
});
// Wait for a touch move event, indicating that they are human.
$('body').on('touchmove', function () {
// Unlock the form.
$application_form.attr('action', '');
$application_form_button.attr('disabled', false);
});
// A tab or enter key pressed can also indicate they are human.
$('body').keydown(function (e) {
if ((e.keyCode === 9) || (e.keyCode === 13)) {
// Unlock the form.
$application_form.attr('action', '');
$application_form_button.attr('disabled', false);
}
});
});
})(jQuery);
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
'use strict'; 'use strict';
$('.form__wagtail-form').each(function () { $('.wagtail-form').each(function () {
var $wagtail_form = $(this); var $wagtail_form = $(this);
var $wagtail_form_button = $wagtail_form.find('button[type="submit"]'); var $wagtail_form_button = $wagtail_form.find('button[type="submit"]');
var wagtail_form_action = $wagtail_form.data('pageurl'); var wagtail_form_action = $wagtail_form.data('pageurl');
......
.link { .link {
&:disabled,
&.is-disabled {
pointer-events: none;
opacity: .5;
}
&--button { &--button {
@include button($color--light-blue, $color--dark-blue); @include button($color--light-blue, $color--dark-blue);
display: inline-block; display: inline-block;
&--narrow { &--narrow {
@include button--narrow; @include button--narrow;
} }
......
.link { .link {
&:disabled,
&.is-disabled {
pointer-events: none;
opacity: .5;
}
&--button { &--button {
@include button($color--light-blue, $color--dark-blue); @include button($color--light-blue, $color--dark-blue);
display: inline-block; display: inline-block;
&--narrow { &--narrow {
@include button--narrow; @include button--narrow;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment