lundi 13 avril 2015

Trouble integrating reCAPTCHA into custom PHP form

I am coming back to some hobby programming after a long absence. I am trying to integrate reCAPTCHA into a custom PHP form and it is driving me mad! I am hoping someone can help.


The form is here: http://ift.tt/1FOSYSR (please no design critique, at least not right now!)


The problem is that the form submits successfully even if the reCAPTCHA is not checked: the code doesn't really affect the form at all, and the process does not 'die' when the captcha is left untouched.


I have wasted hours on this, and I assume I am missing something obvious? I would be so grateful of any help!


Glen



//reCAPTCHA head code
require_once('requires/recaptchalib.php');

$publickey = "###";
$privatekey = "###";


//was there a reCAPTCHA response?
if ($_POST["recaptcha_response_field"]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("Oops, our computer thinks you are a robot. Please click back and try again. reCAPTCHA said: " . $resp->error);
}
}


Then comes the code to insert into the DB.


The form is as follows:



<form target="_self" enctype="multipart/form-data" method="post" name="listing_add" action="">


...



<div align="center" class="g-recaptcha" data-sitekey="###"></div>


...


Aucun commentaire:

Enregistrer un commentaire