Welcome Guest, Not a member yet? Register   Sign In
reCaptcha is_valid returns Trying to get property of non-object when empty
#1

[eluser]javer[/eluser]
Hi,

I need help with reCaptcha validation in codeigniter. Here is my code for validation :
Code:
$resp = $this->recaptcha->recaptcha_check_answer(
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]
);
if ($resp->is_valid)
{                                                        
    echo 'ok';
}
else
{                            
    echo 'fail';
}

It works fine when I enter some text into captcha field. If its correct it prints ok, if not it prints fail. So this is fine. The problem is when I leave captcha response field empty ( dont write there any text) then I get an error:
Trying to get property of non-object
that points to line
Code:
if ($resp->is_valid)

help please Smile
#2

[eluser]javer[/eluser]
I have repaired it. I just checked if recaptcha_response_field is empty and if it is, I dont even call $resp->is_valid.
It looks like this:
Code:
if ($_POST["recaptcha_response_field"] !='' && $resp->is_valid)
{
.....




Theme © iAndrew 2016 - Forum software by © MyBB