Well, this is really bad. The forum is stripping out <scr-ipt> tags.
It looks like this experiment is the way to have them, as I am seeing from previews. So I will put them back in the code below, and you can remove the dashes.
There is also the early line from the above which should read:
You need the <scr-ipt></scri-pt> bracketing of the added var code from the wiki; it all counts. Also, you should be using <head></head> around all of this for your html.
Maybe you had those script tags actually, and had yours stripped too. But anyway, the code below works, has the passed statement, and discussion above. No first-time funny messages.
Best, & good fortune, Clive
<html>
<head>
<scri-pt>
var RecaptchaOptions = {
theme : 'clean'
};
</scri-pt>
</head>
<body>
<form action="" method="post">
<?php
require_once('/home/edalzell/phplib/recaptcha-php-1.10/recaptchalib.php');
$publickey = "";
$privatekey = "";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# are we submitting the page?
# This is where we process the user's response. We don't
# do this when the form is initially displayed - only
# when the user submits it.
if ($_POST["recaptcha_response_field"]) {
$response = recaptcha_check_answer(
$privatekey, $_SERVER['REMOTE_ADDR'],
$_POST['recaptcha_challenge_field'],
$_POST['recaptcha_response_field']
);
if ( $response->is_valid ) {
# The user passed the reCAPTCHA test: form submission should continue
# Your other form validation logic should go here.
# For example
# ... validate user input ...
# ... store form data in a database ...
# ... redirect to 'thank you' page
echo "passed";
}
else {
# The user failed the reCAPTCHA test so we need
# to fill in the error message and re-try the
# form submission
$error = $response->error;
echo "error: ", $error;
}
}
# Display the reCAPTCHA challenge. The first time
# through $error will be null.
echo recaptcha_get_html( $publickey, $error );
?>
<br>
<input type="submit" value="submit" />
</form>
</body>
</html>
Hi - sorry, didn’t spot your reply until today Saturday.
Erin, I see the Notice problem on your site too. I can duplicate it on my own, but not quite exactly, and I think that has to be a clue.
if I put in a bad $privatekey value, then I get your Notice on first start with fresh browser, Firefox as normal, or IE6 that I keep around for checking things.
But. On your site, the Recaptcha works, and doesn’t give more notices or odd errors. On my site, the Recaptch didn’t work with bad privatekey, and instead always gives me error: incorrect-private-key, or near that wording, for right or wrong typed response.
Not Notice after the first page load, but a consistent error on all others which is printed by our error echo coce, be sure to see.
Bad $publickey in a separate test gives different message, and no Notice, is easy to see, so it’s not that.
Here are two things I can suggest.
When you do this, I would leave the directory name the same as they put it for the library, and adjust your code for that. I can’t see what difference this would make but you never know - something in their own idea of security perhaps.
You may not get this note until you get back, but I know you will enjoy vacation.
Regards, Clive
Here is the solution. reCaptcha is looking for a post variable. EE uses {segment_X} to define post variables. So, here is the code that will work. Make sure you set the template to parse PHP on input.
<?php
require_once('recaptchalib.php');
// Get a key from http://recaptcha.net/api/getkey
$publickey = "whatever";
$privatekey = "whatever";
# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;
# was there a reCAPTCHA response?
?>
{if segment_4}
<?php
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
echo "You got it!";
} else {
# set the error code so that we can display it
$error = $resp->error;
}
?>
{/if}
<?php
echo recaptcha_get_html($publickey, $error);
?>
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.