Im trying to test a user’s response from captcha input. Whenever the user inputs an incorrect response, this code works and spits out the error message but when the user inputs a correct response it doesn’t return the success message. In fact, the response is empty. I’ve been playing with this for a couple of days and I have no idea what is going on here.. In fact, I’ve used this structure in other parts of my app and it has work just fine. Any ideas what could be happening?
if ($recaptcha_response_field !== '') {
require_once('recaptchalib.php');
$privatekey = "removed_this_duh...";
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"],
$recaptcha_challenge_field, $recaptcha_response_field);
if (!$resp->is_valid) {
$entry_display = 'Sorry, I know this sucks...
but your entry was invalid, please try again.';
} else {
$entry_display = 'success';
}
return $entry_display;
Here is the client side ajax business:
function(data) {
if (data == 'success') {
alert('success');
$('#mask').hide();
$('#modal_container').hide();
} else {
alert(data);
$('#captcha_error_area').empty().append(data);
javascript:Recaptcha.reload();
}
On success, here is the object I am testing:
Failure:
ReCaptchaResponse Object ( [is_valid] => [error] => incorrect-captcha-sol )
Success:
ReCaptchaResponse Object
(
[is_valid] => 1
[error] =>
)
From the dump of your object, it looks like
is_validmight be NULL or empty when there is an error anderroris filled with something. In this case, I’d switch the order of your if, because1will evaluate totrueand nothing will evaluate tofalse: