我正在尝试在我的页面(HTML 和 PHP)中实现 reCaptcha,但由于某种原因,当我输入文本时,它不起作用。我已经多次验证了私钥和公钥,并且可以确认它们放置正确。我得到的错误如下所示:"The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: "")"
如您所见,错误方法不返回任何内容。这是代码:
表格:
<form action="ticket.php" method="post">
<table>
<tr>
<td>Full Name:</td>
<td><input type="text" name="name" value="<?=(!empty($_POST['name'])) ? $_POST['name'] : ''?>" /></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type="text" name="email" value="<?=(!empty($_POST['email'])) ? $_POST['email'] : ''?>" /></td>
</tr>
<tr>
<td>Topic:</td>
<td><input type="text" name="topic" value="<?=(!empty($_POST['topic'])) ? $_POST['topic'] : ''?>" /></td>
</tr>
<tr></tr>
<tr>
<td>Question:</td>
</tr>
<tr>
<td colspan="2"><textarea cols="30" rows="5" name="question" "<?=(!empty($_POST['question'])) ? $_POST['question'] : ''?>"></textarea></td>
</tr>
<tr>
<td colspan="2">
<?php
require_once('recaptchalib.php');
$publickey = "public key here";
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<br>
<tr>
<td colspan="2" style="text-align:center;"><input type="submit" name="submit" value="Submit Question" /></td>
</tr>
</table>
</form>
PHP:
<html>
<head>
<title></title>
<link href='http://fonts.googleapis.com/css?family=Coda|Oranienbaum|Amarante' rel='stylesheet' type='text/css'>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="wrapper">
<h1><a>Contact Us</a></h1>
</div>
<div class="sidebar">
<div class="sBlock">
<h2>Sidebar</h2>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="about.php">About Us</a></li>
<li><a href="tips.php">Tips</a></li>
<li><a href="services.php">Services</a></li>
<li><a href="contact.php">Contact Us</a></li>
</ul>
</div>
</div>
<div class="contentBody">
<div class="post">
<?
require_once('recaptchalib.php');
$privatekey = "private key here";
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$elements = array('name', 'email', 'topic', 'question');
$valid = true;
$show = true;
if(!empty($_POST['submit'])) {
foreach ($elements as $e) {
if (empty($_POST[$e])) {
echo '<div style="color:red;"> The field ' . $e . ' is required.</div><br />';
$valid = false;
}
}
if (!$resp->isvalid) {
echo '<div style="color:red;"> "The reCAPTCHA wasn\'t entered correctly. Go back and try it again.(reCAPTCHA said: "' . $resp->error . '")"</div><br />';
$valid = false;
}
if ($valid) {
echo '<div style="color:red;"> S\'all good.</div><br />';
}
}
include 'ticket_form.php';
?>
</div>
</div>
<div class="clearfloat"></div>
<footer>
<p class="copyright">
Copyright © <a href="#"></a>
</p>
</footer>
</body>
</html>