I would really apreciate if you could help me.
I have a form that ends with this button:
<button type="submit" value="Create" name="new">Create</button>
And then PHP process it using:
if(isset($_POST['new']) && $_POST['new'] == "Create")
So I'm trying to add reCAPTCHA to it and I have this piece of code:
<?php
require_once('recaptchalib.php'); // reCAPTCHA Library
$pubkey = ""; // Public API Key
$privkey = ""; // Private API Key
if ($_POST['doVerify']) {
$verify = recaptcha_check_answer($privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if ($verify->is_valid) {
# Enter Success Code
//process form
}
else {
# Enter Failure Code
echo "You did not enter the correct words. Please try again.";
}
}
?>
But I have no idea how to link them.
Thanks in advice!
Just do:
<?php
require_once('recaptchalib.php'); // reCAPTCHA Library
$pubkey = ""; // Public API Key
$privkey = ""; // Private API Key
if(isset($_POST['new']) && $_POST['new'] == "Create") {
if ($_POST['doVerify']) {
$verify = recaptcha_check_answer($privkey, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
if ($verify->is_valid) {
# Enter Success Code
//process form
}
else {
# Enter Failure Code
echo "You did not enter the correct words. Please try again.";
}
}
}
?>
Not much point validating the CAPTCHA if the rest of the form doesn't pass validation, right?
let your filename of your "php piece of code" be "capt.php"
change the action of the form to "capt.php"
eg:
action =
"capt.php"
Enjoy!