Notice: Undefined index: recaptcha_response_field in ...........

1,753 views
Skip to first unread message

Scott

unread,
Nov 10, 2009, 11:13:54 PM11/10/09
to reCAPTCHA
Hello Group,

I just came across this Notice when trying to implement reCAPTCHA and
saw some posts about it here so I figured I would post the code that I
used to get it to work, in case it will help anyone else.

-----------------------------------------------------------------

// THIS CODE SHOWS NOTICE MESSAGE

if ($_POST['recaptcha_response_field']) {
$response = recaptcha_check_answer(
$privatekey, $_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);


// THIS CODE DOES NOT SHOW NOTICE MESSAGE

if (isset($_POST['recaptcha_response_field'])) {
$response = recaptcha_check_answer(
$privatekey, $_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);

-----------------------------------------------------------------

1) if ($_POST['recaptcha_response_field']) tests if the field is
equal to 1 (true).

2) if (isset($_POST['recaptcha_response_field'])) tests if the
field has been set (defined).

I believe you would only use 1) as an IF condition if you expect the
condition to be TRUE or FALSE. Whereas 2) tests whether the variable
has been set, which is what you actually want to test, because if it's
set this means the form has been submitted and if it's not set
(undefined) then you want to display the reCAPTCHA.

Scott Shemtov
http://www.shorewebmaster.com/

Charles Sweeney

unread,
Nov 11, 2009, 5:18:44 PM11/11/09
to reCAPTCHA
In addition to the above...

A notice is just that, it's a notice, not an error as it is often seen
as. I would say they are more a nuisance than anything else,
particularly in this case.

If you have a lot of code instances that you would have to change to
make the notice(s) go away, you can simply add a line of code to the
top of your PHP script that is dealing with the form, to suppress the
notices:

error_reporting(E_ALL ^ E_NOTICE);

The above line will report all errors EXCEPT notices.

It should be said, this is a PHP issue and is not peculiar to code
used for reCAPTCHA.

--
Charles Sweeney
http://FormToEmail.com
PHP mail script with reCAPTCHA

Ma. Sheila Magboo

unread,
Nov 20, 2012, 2:17:51 AM11/20/12
to reca...@googlegroups.com, sc...@shorewebmaster.com
Hi Scott, your solution worked! I just added the isset() in the if and it worked! Thanks!

kharis hidayatullah

unread,
Apr 24, 2013, 8:12:03 PM4/24/13
to reca...@googlegroups.com, sc...@shorewebmaster.com
Hi Scott,

Your solution is simple and it works !
Thanks much :)
Reply all
Reply to author
Forward
0 new messages