PHP die()命令错误检查


PHP die() command error checking

我对die()命令有一个问题。我在我的网站上有一个会员注册页面,其动作是另一个php脚本的形式。提交后,页面将被重定向到我的temp_handle.php,并回显错误命令,而不是发出带有正确错误的警报。同样,success方法不会重定向页面。我正在构建前一页的新版本,我已经采用了以前的作者的代码,所以我知道这种方法多少起作用。我正在用bootstrap重新设计它。

...
<form class="form-horizontal" action="2/temp_handle.php" id="registerForm" method="post">
    <input type="text" name="first_name">
</form>
...

这个表单被提交给temp_handle.php执行:

$first_name = sanitize($_POST['first_name']);
if (!$first_name || (strlen($first_name) > 32)) 
    die('error: first_name');

返回注册页面,

$(document).ready(function () {
    $('#registerForm').ajaxForm(function (response) {
        if (response == 'success') {
            alert('Thank you, your registration has been processed.');
            window.location.replace('myURL'); //actual URL in real code
            //TODO redirect to success page
        } else {
            alert('Registration failed, ' + response);
        }
    });
});

而不是打印

错误:first name

任何帮助都是感激的。谢谢你!

看起来你的表单正在以"正常"/非ajax方式提交,所以这意味着javascript:

有问题。
  1. jQuery未加载;
  2. 表单插件未加载;
  3. 你有一个错误在你的javascript(我没有看到任何在你发布的)。