Skip to content

Instantly share code, notes, and snippets.

@tjmaxwell
Created November 28, 2017 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjmaxwell/e2aa18c9e8c29afb66c13a34d5cb545a to your computer and use it in GitHub Desktop.
Save tjmaxwell/e2aa18c9e8c29afb66c13a34d5cb545a to your computer and use it in GitHub Desktop.
For customers that request Captcha. Google ReCaptcha won't work in Shopify for many reason as it has to be server-side submitted and we don't have access to Shopify hosting. So a simple solution is to use a Simple Captcha like this;
<!-- add this right after the textarea html code and before the submit / clear button -->
<!-- Captcha Placement -->
<div class="captcha">
How much is: <input type="text" readonly="readonly" id="question"/>
Answer:* <input type="text" id="answer"/>
</div>
<!-- Captcha Placement -->
{% if template contains 'contact' %}
{{ 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js' | script_tag }}
<script type="text/javascript">
$(document).ready(function() {
var n1 = Math.round(Math.random() * 10 + 1);
var n2 = Math.round(Math.random() * 10 + 1);
$("#question").val(n1 + " + " + n2);
$(".contact-form").submit(function (e) {
if (eval($("#question").val()) != $("#answer").val()) {
$("#answer").css('box-shadow', '0px 0px 7px red');
e.preventDefault();
}
});
});
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment