From 8531410ff5fb89df84d28fb097c236e6c5cb894c Mon Sep 17 00:00:00 2001 From: Dylan Lloyd Date: Tue, 22 Mar 2011 04:10:06 -0400 Subject: [PATCH] rm #email, fixed & prettied recaptcha errors --- includes/ajax.js | 23 +++++++++-------------- includes/style.css | 18 ++++++++++++++++++ index.php | 46 +++++++++++++++++++++++++--------------------- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/includes/ajax.js b/includes/ajax.js index 014e1f5..6e94941 100644 --- a/includes/ajax.js +++ b/includes/ajax.js @@ -1,6 +1,10 @@ $(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(); @@ -13,12 +17,10 @@ $(document).ready(function() { success: function(data) { if (data.split('\n')[0] == 'true') { var name = $("#comment_name").val(); - var email = $("#comment_email").val(); var text = $("#comment_text").val(); if (name == '') { name = "anon" } var comment_data = { "captcha" : "passed", "name" : name, - "email" : email, "text" : text}; $.ajax({ type: "POST", @@ -27,22 +29,15 @@ $(document).ready(function() { url: "verify", data: comment_data, success: function() { - if (email != '') { - var new_post = "

" + name + "

" + var new_post = "

" + name + "

" + text + "

"; - } else { - var new_post = "

" + name + "

" - + text + "

"; - } $('#comments').prepend(new_post); $('#comment').hide(); - console.log('posted new comment'); } }); } else { - var error = "reCAPTCHA said you're not human"; - $('#comment').append(error); + $('#not_human').show(); + $('#recaptcha_response_field').css('border', '2px solid red') } }, error: function() { @@ -53,8 +48,8 @@ $(document).ready(function() { } }); } else { - var error = "but you didn't write anything!
"; - $('#submit').before(error); + $('#blank_comment').show(); + $('#comment_text').css('border', '2px solid red') } return false; }); diff --git a/includes/style.css b/includes/style.css index 9bfd391..c1cdb12 100644 --- a/includes/style.css +++ b/includes/style.css @@ -215,3 +215,21 @@ pre { #recaptcha_widget { display:none; } + +#not_human { + display:none; + font-weight:bold; + font-family:sans-serif; + color:red; + margin-top:15px; + margin-bottom:15px; +} + +#blank_comment { + display:none; + font-weight:bold; + font-family:sans-serif; + color:red; + margin-top:15px; + margin-bottom:15px; +} diff --git a/index.php b/index.php index 7feaa03..687fc69 100644 --- a/index.php +++ b/index.php @@ -385,15 +385,14 @@ class note extends cms { } if (isset($_POST['captcha']) || $resp->is_valid) { $sql = ("INSERT INTO comments (date_posted, author, - email, text, note) - VALUES(NOW(), ?, ?, ?, ?)"); + text, note) + VALUES(NOW(), ?, ?, ?)"); $stmt = $this->db->prepare($sql); // Checks are needed here (no blank text, - // and a default author / email need to be set + // and a default author needs to be set // for no-javascript users. - $stmt->bind_param('ssss', + $stmt->bind_param('sss', htmlspecialchars($_POST['name']), - htmlspecialchars($_POST['email']), htmlspecialchars($_POST['text']), $this->id); $stmt->execute(); @@ -441,20 +440,15 @@ END_OF_NAVIGATION; private function display_comments() { echo "
"; - $sql= "SELECT date_posted, author, email, text + $sql= "SELECT date_posted, author, text FROM comments WHERE note = ? ORDER BY date_posted DESC"; $result = $this->query($sql, 'd', $this->id); foreach ($result as $row => $entry) { $date_posted = $entry['date_posted']; $author = $entry['author']; - $email = $entry['email']; $text = htmlspecialchars($entry['text']); - if ($email == '') { - $head = "

$author

"; - } else { - $head = "

$author

"; - } + $head = "

$author

"; echo << $head @@ -487,8 +481,6 @@ END_CAPTCHA_STYLE;

name:

-

email:

-
@@ -497,7 +489,7 @@ END_CAPTCHA_STYLE; ( another / audio / - Get an image CAPTCHAhelp ) + imagehelp )

@@ -510,19 +502,31 @@ END_CAPTCHA_STYLE; END_OF_FORM; echo recaptcha_get_html($this->recaptcha_publickey); if ($this->failed_captcha) { - echo <<reCAPTCHA said you're not human, - + echo << + reCAPTCHA said you're not human,
+ try again? +
+
-END_OF_FORM; +END_OF_ERRORS; } else { - echo << + reCAPTCHA said you're not human,
+ try again? + +
+ but you didn't write anything!
+
+END_OF_ERRORS; + } + echo << END_OF_FORM; - } } } -- 2.30.2