X-Git-Url: https://disinclined.org/git/?a=blobdiff_plain;f=includes%2Fcomment_validation.js;fp=includes%2Fcomment_validation.js;h=6e94941e5c56337ce2936c6419157d973210148f;hb=69fc1a7b8b5406160484cb657881ab9623ec0630;hp=0000000000000000000000000000000000000000;hpb=353b047dd912955763184787347927b58bd0e84f;p=dylansserver.git diff --git a/includes/comment_validation.js b/includes/comment_validation.js new file mode 100644 index 0000000..6e94941 --- /dev/null +++ b/includes/comment_validation.js @@ -0,0 +1,56 @@ +$(document).ready(function() { + $('#recaptcha_widget').show(); + $('.submit').click(function() { + $('#not_human').hide(); + $('#blank_comment').hide(); + $('#comment_text').css('border', '1px solid grey') + $('#recaptcha_response_field').css('border', '1px solid grey') + if ($('#comment_text').val() != '') { + var challenge = Recaptcha.get_challenge(); + var response = Recaptcha.get_response(); + var captcha_data = { "challenge" : challenge, + "response" : response}; + $.ajax({ + type: "GET", + url: "/captcha", + data: captcha_data, + success: function(data) { + if (data.split('\n')[0] == 'true') { + var name = $("#comment_name").val(); + var text = $("#comment_text").val(); + if (name == '') { name = "anon" } + var comment_data = { "captcha" : "passed", + "name" : name, + "text" : text}; + $.ajax({ + type: "POST", + // the url may need to be adjusted for + // trailing slashes + url: "verify", + data: comment_data, + success: function() { + var new_post = "

" + name + "

" + + text + "

"; + $('#comments').prepend(new_post); + $('#comment').hide(); + } + }); + } else { + $('#not_human').show(); + $('#recaptcha_response_field').css('border', '2px solid red') + } + }, + error: function() { + console.log('error'); + }, + complete: function() { + Recaptcha.reload(); + } + }); + } else { + $('#blank_comment').show(); + $('#comment_text').css('border', '2px solid red') + } + return false; + }); +});