Created
January 31, 2012 17:08
-
-
Save jcroft/1711625 to your computer and use it in GitHub Desktop.
Preventing comment spam
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
COMMENTS_SECRET = 'any_old_string_you_like' |
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
<input type="hidden" name="comment-secret" id="id_comment-secret" /> | |
<textarea id="id_comment-body" rows="10" cols="40" name="comment-body"></textarea> |
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
<script type="text/javascript"> | |
$('textarea#id_comment-body').keypress(function() { | |
setTimeout(function(){ | |
$('input#id_comment-secret').attr('value', '{% setting 'COMMENTS_SECRET' %}') | |
}, | |
5000) | |
}); | |
</script> |
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
def clean(self): | |
if not self.request.POST.get('comment-secret', '') == settings.COMMENTS_SECRET: | |
raise forms.ValidationError("This site thinks you're a spammer. If you're not, wait a few seconds after typing your comment before you submit it.") | |
return self.cleaned_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment