Skip to content

Instantly share code, notes, and snippets.

@jeremyricketts
Last active August 29, 2015 14:03
Show Gist options
  • Save jeremyricketts/7d54c39422537dd5c2f1 to your computer and use it in GitHub Desktop.
Save jeremyricketts/7d54c39422537dd5c2f1 to your computer and use it in GitHub Desktop.
Three checks. 1) no value for hidden html input, 2) updated value using javascript, 3) 5 second minimum required to fill out a form.
<form>
<!-- If this has any value, ever, it's spam. Human's don't fill out hidden inputs. -->
<input type="hidden" class="spmChkOne">
<!-- If this has anything other than 'ntSpm', it's spam. Bot tried to fill it out sans js. -->
<input type="text" class="spmChkTwo" value="spm">
<!-- If this has anything other than 'ntSpm', it's spam. Humans need more than 5 seconds. -->
<input type="text" class="spmChkThree">
</form>
<script>
$(function() {
/*
=============================
Prevent sp@m
============================= */
$('.spmChkTwo, .spmChkThree').hide();
$('.spmChkTwo').val('ntSpm');
spm5sec = setTimeout(spm5secGo, 5000);
function spm5secGo() {
$('.spmChkThree').val('ntSpm');
clearTimeout(spm5sec);
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment