Php 在我的表单中添加reCaptcha
我试图在我的页面(HTML和PHP)中实现reCaptcha,但由于某种原因,当我输入文本时,它不起作用。我已经多次验证了私钥和公钥,我可以确认它们放置正确。我返回的错误如下所示:Php 在我的表单中添加reCaptcha,php,html,captcha,Php,Html,Captcha,我试图在我的页面(HTML和PHP)中实现reCaptcha,但由于某种原因,当我输入文本时,它不起作用。我已经多次验证了私钥和公钥,我可以确认它们放置正确。我返回的错误如下所示:“没有正确输入reCAPTCHA。请返回并重试。(reCAPTCHA说:”错误方法不会返回任何内容,如您所见。代码如下: 表格: <form action="ticket.php" method="post"> <table> <tr>
“没有正确输入reCAPTCHA。请返回并重试。(reCAPTCHA说:”
错误方法不会返回任何内容,如您所见。代码如下:
表格:
<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>
全名:
-您的本地主机版本是否正常工作?(记住,localhost或仅127.0.0.1)我直接在托管站点中进行测试。合乎逻辑的做法是使用reCaptcha制作尽可能简单的表单,并在本地服务器上进行测试,然后使用var_dump()输出您似乎已经安装并依赖的此类。仅仅使用谷歌提供的例子有什么不对?
<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>