0

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

我的表单页面

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

上面的 die 出现了 teklif.php,它看起来很奇怪。我希望模具消息显示在表单页面中,我的意思是同一页面。有什么解决办法吗?(对不起我的英语不好。)

4

1 回答 1

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 属性设置为“提交”。现在将此代码放在下面。

<form id="freeform" method="post" action="" onsubmit="return validate_form(this)">
    <?php echo recaptcha_get_html($publickey); ?>
</form>
于 2012-05-06T11:51:47.523 回答