reCAPTCHA Form Fields not working?

49 views
Skip to first unread message

Wizzums

unread,
Sep 24, 2009, 8:42:53 PM9/24/09
to reCAPTCHA
I have the reCAPTCHA between my form tags, yet the form fields never
make it through. I have setup a print_r to dump the contents of the
$_POST array, and it does, but no captcha fields exist in it. Here's
the site in question:
http://www.watcheslikenew.com/sendtofriend.php?id=1273 .. after
hitting submit, you must view the source and review line 150. You
will see the variables being passed through $_POST. When I set my
configuration to display PHP errors, it tells me that
"recaptcha_challenge_field" and "recaptcha_response_field" are not
valid indexes for $_POST. Any ideas?

Here's a snippit of my code:

<? include ("inc/constants.php") ?>
<? include ("inc/header.php") ?>
<? require_once('recaptchalib.php'); // for captcha ?>
<? $publickey = "..."; // for captcha ?>
<p class="heading">SEND THIS PAGE TO A FRIEND</p>
<script type="text/javascript">
var RecaptchaOptions = { theme : 'white' };
</script>
<?
if ($process == 1) {
print "<!-- <pre>";
print_r($_POST);
print $recaptcha_challenge_field;
print "</pre> -->";
$error = "";

$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
$error = $resp->error;
$id = $_POST['PID'];
} else {
$subject = "$name wants you to see this item at WatchesLikeNew.com";
$mailcontent = "Hello,<br>\nI found this watch at WatchesLikeNew.com
and thought you might find it of interest.<br>\n<br>\n";
$mailcontent = $mailcontent."Link: <a href=\"http://
www.watcheslikenew.com/detail.php?id=".$PID."\">http://www.watcheslikenew.com/detail.php?id=".$PID."</a>";
$toaddress = $emailto;
$fromaddress = $email;
mail($toaddress, $subject, $mailcontent, "From: $name <$fromaddress>
\nReply-To: $name <$fromaddress>\nContent-type: text/html");

echo "<p>Thank you. An email has been sent to your friend.<br><br><a
href=\"detail.php?id=$PID\">Click here to return to that watch</a>.</
p>";
$sent = true;
}
}

if (!isset($sent)) {
$sql="SELECT * FROM T1Brands,T2Watches WHERE T1BrandsID = T2BrandsFK
AND T2WatchesID = $id";
$result=mysql_query($sql,$db);

$num = mysql_num_rows($result);

if ($num > 0) {
$row = mysql_fetch_array($result);
?>
<table border="0" cellspacing="0" cellpadding="3" align="center">
<form method="post" action="sendtofriend.php">
<input type="hidden" name="process" value="1">
<input type="hidden" name="PID" value="<?=$id?>">
<tr>
<td class="blue"><b>Inventory #:</b>&nbsp;</td>
<td><?=$row["T2Sku"]?></td>
<td rowspan="5" align="right" valign="top">
<table border="0" cellspacing="0" cellpadding="1"
bgcolor="#6666CC">
<tr>
<td><a href="detail.php?id=<?=$id?>"><img src="/images/p/<?=$row
["T2Image1"]?>" width="82" height="122" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="blue"><b>Brand:</b></td>
<td><?=$row["T1BrandsName"]?></td>
</tr>
<tr>
<td class="blue"><b>Model:</b></td>
<td><?=$row["T2Model"]?></td>
</tr>
<tr>
<td class="blue"><b>Status:</b></td>
<td><?=$row["T2Status"]?></td>
</tr>
<tr>
<td class="blue"><b>Price:</b></td>
<td>$<?=$row["T2Price"]?></td>
</tr>
<tr>
<td><br><br></td>
</tr>
<tr>
<td><b>Friend's Email:</b></td>
<td colspan="2"><input type="text" name="emailto" size="30"
class="input200" value="<? echo (isset($_POST['emailto'])?$_POST
['emailto']:""); ?>"></td>
</tr>
<tr>
<td><b>Your Name:</b></td>
<td colspan="2"><input type="text" name="name" size="30"
class="input200" value="<? echo (isset($_POST['name'])?$_POST
['name']:""); ?>"></td>
</tr>
<tr>
<td><b>Your Email:</b></td>
<td colspan="2"><input type="text" name="email" size="30"
class="input200" value="<? echo (isset($_POST['email'])?$_POST
['email']:""); ?>"></td>
</tr>
<tr>
<td colspan="2" align="center"><? echo recaptcha_get_html
($publickey, $error); ?></td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" name="submit"
value="Submit" class="button"></td>
</tr>
</form>
</table>
<? } else { echo "Sorry, that product no longer exists."; }
} ?>
<? include ("inc/footer.php") ?>

Justin

unread,
Sep 25, 2009, 7:09:04 PM9/25/09
to reCAPTCHA
On Sep 24, 5:42 pm, Wizzums <wizz...@gmail.com> wrote:
> I have the reCAPTCHA between my form tags, yet the form fields never
> make it through.  I have setup a print_r to dump the contents of the
> $_POST array, and it does, but no captcha fields exist in it.  Here's
> the site in question:http://www.watcheslikenew.com/sendtofriend.php?id=1273.. after
> hitting submit, you must view the source and review line 150.  You
> will see the variables being passed through $_POST.  When I set my
> configuration to display PHP errors, it tells me that
> "recaptcha_challenge_field" and "recaptcha_response_field" are not
> valid indexes for $_POST.  Any ideas?

I am having basically the same problem, but with perl. The reCAPTCHA
box shows up, but any entry is allowed through. I have tried to
output the form fields to see if they ever get populated, and they
don't seem to be. I am probably missing something trivial, but I
don't see it yet. Here is a code snippit:
use CGI;
use CGI qw(:standard *table *TR *th *td *ul *ol);
use Captcha::reCAPTCHA;

my $q = CGI->new();
my $c = Captcha::reCAPTCHA->new();

my $error = undef;
my $captcha_html = $c->get_html( $pubkey, $error );

print $q->header();


print $q->start_html( -title=>$page_title,
-style=>{'src'=>$page->stylesheet}
);
print $page->start_body();

print $q->start_table( {-border=>'0',
-cellspacing=>'10',
-cellpadding=>'5',
-width=>'90%',
-align=>'CENTER'} );
print $q->start_form();

print $q->Tr( {-align=>'CENTER', -nowrap=>'nowrap'},
$q->td( {-align=>'CENTER', -valign=>'CENTER', -
colspan=>'2'},
"<h1>Suggestions? Comments? Please let us
know.</h1>" )
);
# bunch of print $q->Tr statements)
print $q->Tr( {-align=>'CENTER',
-valign=>'CENTER',
-nowrap=>'nowrap'},
# -class=>'searchbody'},
$q->td( {-align=>'RIGHT', -valign=>'CENTER'},
"&nbsp;&nbsp;&nbsp;" ),
$q->td( {-align=>'LEFT', -valign=>'CENTER'},
# here is where the recaptcha box is printed
$captcha_html)
);
print $q->end_form();
print $q->end_table();

print "recaptcha_response_field = ".$q->param
('recaptcha_response_field')."<br>";
print "recaptcha_challenge_field = ".$q->param
('recaptcha_challenge_field')."<br>";
print "email = ".$q->param("email")."<br>";

The email line is successfully printed out, but the recaptcha fields
are empty.

It seems like we have similar problems here.

Justin

unread,
Sep 26, 2009, 2:06:22 PM9/26/09
to reCAPTCHA
On Sep 25, 4:09 pm, Justin <justin.el...@gmail.com> wrote:
> On Sep 24, 5:42 pm, Wizzums <wizz...@gmail.com> wrote:
>
> > I have the reCAPTCHA between my form tags, yet the form fields never
> > make it through.  I have setup a print_r to dump the contents of the
> > $_POST array, and it does, but no captcha fields exist in it.  Here's
> > the site in question:http://www.watcheslikenew.com/sendtofriend.php?id=1273.. after
> > hitting submit, you must view the source and review line 150.  You
> > will see the variables being passed through $_POST.  When I set my
> > configuration to display PHP errors, it tells me that
> > "recaptcha_challenge_field" and "recaptcha_response_field" are not
> > valid indexes for $_POST.  Any ideas?
>
> I am having basically the same problem, but with perl.  The reCAPTCHA
> box shows up, but any entry is allowed through.  I have tried to
> output the form fields to see if they ever get populated, and they
> don't seem to be.  I am probably missing something trivial, but I
> don't see it yet.  Here is a code snippit:

Well, I seem to have solved my problem. In my case I was starting the
form after the table. Swapping these fixed my problem. I don't know
if this helps you out, but you might try swapping where the form and
table tags are started and ended.

Hope that helps you out too.

Wizzums

unread,
Sep 28, 2009, 5:00:47 PM9/28/09
to reCAPTCHA
Wow, thank you!! I didn't even think of that. This isn't a site
originally developed by us and I didn't even notice the form fields
being embedded in the table.

Anyway, this fixed the issue. Thanks again.

Charles Sweeney

unread,
Sep 29, 2009, 8:51:52 AM9/29/09
to reCAPTCHA
A quick blast through the W3C code validator:

http://validator.w3.org/

...would have shown the error with the form and table tags.

If you declare a doctype, the browser will work to it, so you must
too.

--
Charles Sweeney
http://FormToEmail.com
PHP mail script with reCAPTCHA
Reply all
Reply to author
Forward
0 new messages