Undefined index: recaptcha_challenge_field

2,585 views
Skip to first unread message

Maruz

unread,
Nov 26, 2009, 2:50:36 PM11/26/09
to reCAPTCHA
Hi, I'm trying to implement a reCAPTCHA to a register user page in
PHP, but I continue to get a warning, and my users don't get
registered in the database. Before trying to add reCAPTCHA the
registration worked as it should.

Warning 1: Undefined index: recaptcha_challenge_field (line that gives
this warning is $_POST["recaptcha_challenge_field"],)

Warning 2: Undefined index: recaptcha_response_field (line that gives
this warning is $_POST["recaptcha_response_field"]);)

The error message that get's displayed is: incorrect-captcha-sol

It doesn't matter what I try, I've googled the problems described
above and tried for several hours now to solve it, none of the
suggested solutions I've found worked, and I need some help with
this...

------------------ My Code ---------------------
<?php
// reCAPTCHA stuff
require_once('recaptchalib.php');
$publickey = "...";
$privatekey = "...";
// Tripplechecked that the keys are correct!

$resp = null;
$error = null;
// end reCAPTCHA stuff

if($_POST)
{
$username = $_POST['username'];
$password = $_POST['password'];
$confirm = $_POST['confirm'];
$email = $_POST['email'];

// Some checks to see if data was entered in the form
if($username == "")
{
// Logic for checking data
}
else
{
// Connect to database and check for already existing user names /
e-mails
// If none found, proceed with the below code

// reCAPTCHA stuff
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if(!$resp->is_valid)
{
echo $resp->error;
}// end reCAPTCHA stuff
else
{
// Register new user in database
}
}
}
?>

<html>
<head>
<title>Title</title>
<script type= "text/javascript">
var RecaptchaOptions = {
theme: 'clean'
};
</script>
</head>

<body>

<h1>Welcome!</h1>
<table border="0"><form method='post' action='register.php'>
<tr><td colspan="2" width="320" align="center"><b>Register a new
account:</b></td></tr>
<tr><td align="right">Username: </td><td><input type='text'
name='username' /></td></tr>
<tr><td align="right">Password: </td><td><input type='password'
name='password' /></td></tr>
<tr><td align="right">Confirm Password: </td><td><input
type='password' name='confirm' /></td></tr>
<tr><td align="right">E-mail Adress: </td><td><input type="text"
name="email" /></td></tr>
<tr><td colspan="2">

<?php
// reCAPTCHA stuff
echo recaptcha_get_html($publickey, $error);
?>

</td></tr>
<tr><td colspan="2" align="center"><input type='submit'
value='Register!' /></td></tr>
</table></form>

</body>
</html>
---------------------------------------------

Charles Sweeney

unread,
Nov 26, 2009, 5:32:38 PM11/26/09
to reCAPTCHA
Maruz wrote:
> Hi, I'm trying to implement a reCAPTCHA to a register user page in
> PHP, but I continue to get a warning, and my users don't get
> registered in the database. Before trying to add reCAPTCHA the
> registration worked as it should.
>
> Warning 1: Undefined index: recaptcha_challenge_field (line that gives
> this warning is $_POST["recaptcha_challenge_field"],)
>
> Warning 2: Undefined index: recaptcha_response_field (line that gives
> this warning is $_POST["recaptcha_response_field"]);)

Hi Maruz.

Those warnings are "notices". You can make them go away, and fix your
problem, by putting this line of code at the top of your script (just
under <?php):

error_reporting(E_ALL ^ E_NOTICE);

It supresses the notices.

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

Maruz

unread,
Nov 29, 2009, 8:33:34 AM11/29/09
to reCAPTCHA
Well yeah, I've seen that and it does, but it doesn't solve the
problem I have that with the recaptcha set up, I can't get users
registered, but it worked before I tried to implement recaptcha (and
still does if I comment recaptcha out from the code). So, it isn't the
notices that's the problem here.

What about the error message? "incorrect-captcha-sol"

Clookster

unread,
Nov 29, 2009, 8:44:59 AM11/29/09
to reCAPTCHA
First of all, you might want to correct your html
<table><form></table></form> to something like: <table><form></form></
table>

This might sound ridiculous, but I've been trying to get it working
yesterday too, and I had many troubles (because I wanted to combine it
with drupal & jQuery etcetera) so I read quite some problems yesterday
and one was from a man having a similar problem and he solved it by
changing the table/form order, I can't remember 100% which of the two
it was exactly, but try both:
1) form inside table: <table><form></form></table>
2) table inside form: <form><table></table></form>

one of the two options worked and the other didn't, maybe this helps
you too, can't find the link anymore though
if it works, let it know

Maruz

unread,
Nov 29, 2009, 2:08:05 PM11/29/09
to reCAPTCHA
Yeah, I remember reading that myself and tried both combinations.
Tried again too after your post, but still got the same problem.

Edit: Not sure if this actually was the problem or not. It somehow
works now though, so probably (even though I'm pretty sure I tried
this with negative results earlier).

RS

unread,
Sep 7, 2012, 12:50:54 AM9/7/12
to reca...@googlegroups.com
thanku for the answers. changing form and table tags' order solve the problem

Konstantinos Poimenidis

unread,
Feb 21, 2013, 12:40:36 PM2/21/13
to reca...@googlegroups.com
Exactly the same problem as Maruz. Spend a few hours trying to find the problem
and it was solved your way Clookster. Thank you for sharing.
Ridiculously simple but no way to think of it. Thanks a lot!!!

Sherif Riad

unread,
Jun 17, 2013, 3:11:49 PM6/17/13
to reca...@googlegroups.com
always test your variables prior checking its value to avoid such notice and get a clean code, try something like this concept:

if ($myVariable)
{
   
// $myVariable is set and you can use it //
    if ($myVariable == ............... bla bla
}
else
{
   
// $myVariable is not set then you ignore the proccess and avoid the notice //
}

Michael Rolfsmeyer

unread,
Jul 31, 2013, 4:33:44 PM7/31/13
to reca...@googlegroups.com
Clookster's solution worked for me me. When using tables with forms, use <form><table>...reCAPTCHA stuff....</table></form>

Edward McKnight

unread,
Jun 14, 2014, 7:34:27 AM6/14/14
to reca...@googlegroups.com
Also just confirming that putting the <form> tags outside of the <table> tags solved the problem for me also.
Reply all
Reply to author
Forward
0 new messages