使用简单的联系表单,我正在尝试集成Google ReCaptcha以消除我开始接收的垃圾邮件。
现在正在检查ReCaptcha是否成功。如果不是,它只是重新加载页面并重置表单。如果是的话,我希望它能够激活接收联系表单php页面并随之传递表单值。
它正挂在那一部分上。任何帮助将不胜感激。
<?php
// grab ReCaptcha library
require_once "recaptchalib.php";
// your secret key
$secret = "XXXXXXXXXXXXXXXXXXXXXXXX";
// empty response
$response = null;
// check secret key
$reCaptcha = new ReCaptcha($secret);
// if submitted check response
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contact Form</title>
<link href='https://fonts.googleapis.com/css?family=Work+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="assets/form-basic.css">
</head>
<body>
<div class="main-content">
<?php
$action = '';
if ($response != null && $response->success) {
$action = "contactengine.php";
} else {
?>
<form class="form-basic" action="<?php echo $action ?>" method="post">
<div class="form-title-row">
<h1>Get in Touch</h1>
</div>
<div class="form-row">
<input type="text" name="Name" placeholder="Name" required>
</div>
<div class="form-row">
<input type="email" name="Email" placeholder="Email" required>
</div>
<div class="form-row">
<textarea name="Message" placeholder="Message" required></textarea>
</div>
<div class="form-row">
<div class="g-recaptcha" data-sitekey="fdgafafdadfgsdfgrafgaRlifgsfgserysrtyc3H"></div>
</div>
<div class="form-row">
<button type="submit" name="submit" value="submit">Send</button>
</div>
</form>
<?php } ?>
</div>
<script src='https://www.google.com/recaptcha/api.js?hl=en'></script>
</body>
</html>
答案 0 :(得分:1)
您可以将验证码检查代码移动到接收联系表单页面,或者在主页面中添加联系表单处理逻辑。您可能想要使用最后一种方法。