Recaptcha和外部形式的后期行动?

时间:2013-11-29 21:42:11

标签: php recaptcha

我正在尝试使用php库为google的reCAPTCHA向外部网址发布操作,如下所示:

<?php
require_once('recaptchalib.php');

$publickey = "***";
$privatekey = "***";

$resp = null;
$error = null;

if ($_POST["recaptcha_response_field"]) {
        $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
  }
}
?>
<form action="https://www.salesforce.com" method="POST">
    <input type="hidden" name="oid" value="00DA0000000HSo1">
    <input type="hidden" name="00NG0000007s5J1" value="Contact Us">
    <input type="hidden" name="retURL" value="{siteurl}contact-thank-you.html">
    <table>
        <tr>
            <td width="12%" align="right"><label for="first_name">First Name</label></td>
            <td width="210px"><input id="first_name" maxlength="40" name="first_name" size="20" type="text" class="inputbox" /></td>
            <td width="12%" align="right"><label for="last_name">Last Name</label></td>
            <td width="210px"><input id="last_name" maxlength="80" name="last_name" size="20" type="text" class="inputbox" /></td>
        </tr>
        <tr>
            <td align="right"><label for="email">Email</label></td>
            <td><input  id="email" maxlength="80" name="email" size="20" type="text" class="inputbox" /></td>
            <td align="right"><label for="phone">Phone</label></td>
            <td><input  id="phone" maxlength="40" name="phone" size="20" type="text" class="inputbox" /></td>
        </tr>
        <tr>
            <td align="right"><label for="company">Company</label></td>
            <td><input  id="company" maxlength="40" name="company" size="20" type="text" class="inputbox" /></td>
            <td align="right"><label for="URL">Website</label></td>
            <td><input  id="URL" maxlength="80" name="URL" size="20" type="text" class="inputbox" /></td>
        </tr>
    </table>    
<?php
echo recaptcha_get_html($publickey, $error);
?>
                <input type="submit" name="submit" value="Submit"></td>
        </tr>
        <tr>
            <td height="30"></td>
        </tr>
    </table>
    <input  id="00NA0000000Ujum" maxlength="255" name="00NA0000000Ujum" size="20" type="hidden" value="{referrer}" />
</form>

如何使用同一页面使用reCaptcha验证表单,如果正确的话 将用户发送到外部操作? 我也试过这个:

<?php
require_once('recaptchalib.php');
$publickey = "***";
$privatekey = "***";


$resp = null;

$error = null;

if ($_POST["recaptcha_response_field"]) {
        $resp = recaptcha_check_answer ($privatekey,
                                        $_SERVER["REMOTE_ADDR"],
                                        $_POST["recaptcha_challenge_field"],
                                        $_POST["recaptcha_response_field"]);

        if ($resp->is_valid) {
                $action = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
        } else {

            echo $error;
                $error = $resp->error;
        }
}
?>
<form action="<?php echo $action; ?>" method="POST">

</form>

0 个答案:

没有答案