reCaptcha显示错误同一页面

时间:2012-05-06 11:45:18

标签: php recaptcha

如何在同一页面显示错误?

我的表单页

<form id="freeform" method="post" action="/wp-content/themes/ecobiz/teklif.php" onsubmit="return validate_form(this)">
...
<?php
          require_once(ABSPATH. '/wp-content/themes/ecobiz/recaptchalib.php');
          $publickey = "6LeZGdESAAAAAOhZ0SRqLWXcq4TauDK9CUoZhNP8"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
....
</form>

teklif.php

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 . ")");
  }

以上模具显示teklif.php,看起来很奇怪。我希望模板信息显示在表单页面中我的意思是同一页面。有什么解决方案吗? (抱歉我的英文。)

1 个答案:

答案 0 :(得分:0)

将php代码放在页面顶部,并将表单元素的action属性留空。

例如

<?php
require_once(ABSPATH. '/wp-content/themes/ecobiz/recaptchalib.php');
$publickey = "6LeZGdESAAAAAOhZ0SRqLWXcq4TauDK9CUoZhNP8";
//If form is submitted
if(isset($_POST['submit']) {
    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 . ")");
  }
}
?>

我假设您有input="submit",其name属性设置为&#39;提交&#39;。现在将此代码放在下面。

<form id="freeform" method="post" action="" onsubmit="return validate_form(this)">
    <?php echo recaptcha_get_html($publickey); ?>
</form>