Add Google reCAPTCHA
-
Can I add Google reCAPTCHA to Contact Form 7? If yes, what file(s) do I add either the shortcode or the PHP code to?
Using the shortcode is the easiest, if I knew where to put it? If its possible to use the shortcode, could you tell me where I incorporate it in Contact Form 7?
(To view Google reCAPTCHA implementation https://developers.google.com/recaptcha/docs/php)
This plugin gives several options to integrate with the form. A shortcode [bws_google_captcha] (which works great when the plugin is installed and activated in WP, but it needs to be integrated into Contact Form 7 to be effective)
OR integrating it into the PHP file:
require_once(‘recaptchalib.php’);
$publickey = “your_public_key”; // you got this from the signup page
echo recaptcha_get_html($publickey);Which would look like this:
<html>
<body> <!– the body tag is required or the CAPTCHA may not show on some browsers –>
<!– your HTML content –><form method=”post” action=”verify.php”>
<?php
require_once(‘recaptchalib.php’);
$publickey = “your_public_key”; // you got this from the signup page
echo recaptcha_get_html($publickey);
?>
<input type=”submit” />
</form><!– more of your HTML content –>
</body>
</html>— And also the verify.php file
<?php
require_once(‘recaptchalib.php’);
$privatekey = “your_private_key”;
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die (“The reCAPTCHA wasn’t entered correctly. Go back and try it again.” .
“(reCAPTCHA said: ” . $resp->error . “)”);
} else {
// Your code here to handle a successful verification
}
?>
- The topic ‘Add Google reCAPTCHA’ is closed to new replies.