There are 2 parts to using reCAPTCHA. The first part is adding the reCAPTCHA field to your form, which it looks like you've done. The second part is checking the answer that people submit against the image.
That portion needs to be added to your code that you execute to handle the form submission (during your validation, prior to inserting it in to the database. The reCAPTCHA site has some pretty useful documentation about both steps and some sample code you can start with (see the "Server Side" section for the part you are missing).
if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification }
// Validate POTS vars if (!exc_not_null($title)) { $error = true; $title_error = true; } if (!exc_not_null($author_name)) { $error = true; $author_name_error = true; } if (!exc_not_null($author_phone)) { $error = true; $author_phone_error = true; } if (!exc_not_null($text)) { $error = true; $text_error = true; }
//$db = new Database($theDB); $db->query($query); $db->close();
// Email council to approve $email_message = "A new community news item has been added and requires approval.\n"; $headers = 'From: info@feockpc.com' . "\r\n". 'Bcc: jodie@cnx-solutions.com' . "\r\n" . 'Reply-To: info@feockpc.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail('alan@feockpc.com', 'New Community Content', $email_message, $headers);
// all is well - say so! print "<h1>COMMUNITY NEWS ITEM ADDED</h1>\n"; print "<p class=\"centered\">The news item was successfully added to the system and is awaiting approval by our moderators.</strong></p>\n"; print "<p class=\"centered\"><a href=\"community-news.php\">Click here</a> to return to the community news listings.</strong></p>\n";
<h1>ADD YOUR NEWS</h1> <P>Fill in the form below to submit your news to our community pages. Once you have submitted your news it will be sent to our moderators and will be displayed to the public once it is approved.</p>
<h2>Title</h2> <?php if ($title_error == true) { print "<p class=\"formerror\">Please add a title to your news.</p>\n"; } ?> <p><input name="title" size="45" maxlength="50" <?php if(exc_not_null($title)) { echo 'value="' . $title . '"'; } ?> /></p>
<h2>Author</h2> <p>This is for our refernce only and is not visible to public.</p> <?php if ($author_name_error == true) { print "<p class=\"formerror\">Please enter your name in the box below.</p>\n"; } ?> <p><input name="author_name" size="45" maxlength="50" <?php if(exc_not_null($author_name)) { echo 'value="' . $author_name . '"'; } ?> /></p>
<h2>Phone Number for Author</h2> <p>This is for our refernce only and is not visible to public.</p> <?php if ($author_phone_error == true) { print "<p class=\"formerror\">You must supply your contact number, in case we need to contact you. <br />This number will never be given to the public without your consent.</p>\n"; } ?> <p><input name="author_phone" size="45" maxlength="20" <?php if(exc_not_null($author_phone)) { echo 'value="' . $author_phone . '"'; } ?> /></p>
<h2>Phone Number for Public Contact (Optional)</h2> <p><input name="contact_phone" size="45" maxlength="20" <?php if(exc_not_null($contact_phone)) { echo 'value="' . $contact_phone . '"'; } ?> /></p>
<h2>Text</h2> <?php if ($text_error == true) { print "<p class=\"formerror\">Please type your news in the box below.</p>\n"; } ?> <p><textarea cols="50" rows="10" name="text"> <?php if(exc_not_null($text)) { echo $text; } ?></textarea></p>
<h2>Image (Optional)</h2> <p>Your image should be square in its dimentions and less than 1MB in size.</p> <?php if ($file_exists_error == true) { print "<p class=\"formerror\">Error: A file with this name already exists on the server. Please change the filename and try again.</p>\n"; } if ($file_size_error == true) { print "<p class=\"formerror\">Error: File size too large.</p>\n"; } if ($no_file_error == true) { print "<p class=\"formerror\">Warning: No file uploaded.</p>\n"; } ?> <p><input type="file" name="image" /></p> <h2>Captcha Form</h2> <p>Please enter the words in the box below to prove your human.</p> <div style="margin-left:30px;"><p><?php require_once('recaptchalib.php'); $publickey = "6LcYbswSAAAAAGO0LKVW1stPQS6bdeFnYKPrhYMN"; echo recaptcha_get_html($publickey); ?></p></div> <p><input type="submit" value="Sumbit News" class="normal" /></p> </form> <?php }
include("includes/footer.inc.php"); ?>
You can see i added the validation to ($action=='addnow')
Last edited by Inigoesdr; 11-30-2012 at 12:32 AM..