-
-
Save kartick14/ee03a56da7df903bcac81c9d08f9886d to your computer and use it in GitHub Desktop.
Simple "Captcha" for Shopify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Goes in theme.liquid | |
{% 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 %} | |
// page.contact.liquid | |
<div class="rte"> | |
{{page.content}} | |
{% form 'contact' %} | |
{% if form.posted_successfully? %} | |
Thanks for contacting us! We’ll get back to you soon. | |
{% endif %} | |
{% if form.errors %} | |
{% for field in form.errors %} | |
{{ field }} - {{ form.errors.messages[field] }}<br /> | |
{% endfor %} | |
{% endif %} | |
<input type="text" name="contact[name]" placeholder="name" /> | |
<input type="text" name="contact[email]" placeholder="email address" class="{% if form.errors contains 'email' %}input-error{% endif %}" /> | |
<textarea name="contact[body]" rows="20" cols="20" placeholder="message" class="{% if form.errors contains 'body' %}input-error{% endif %}"></textarea> | |
<div class="captcha"> | |
How much is: <input type="text" readonly="readonly" id="question"/> | |
Answer:* <input type="text" id="answer"/> | |
</div> | |
<button type="submit">Send</button> | |
{% endform %} | |
</div> <!-- end .rte --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment