Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用jQuery提交表单,然后更新表单以显示错误,不允许再次提交表单_Php_Jquery_Html_Forms - Fatal编程技术网

Php 使用jQuery提交表单,然后更新表单以显示错误,不允许再次提交表单

Php 使用jQuery提交表单,然后更新表单以显示错误,不允许再次提交表单,php,jquery,html,forms,Php,Jquery,Html,Forms,我正在通过PHP函数显示一个表单: function getLoginForm($errors = false) { $output .= '<form action="#" name="login" method="post" />'; $output .= '<h2>Sign in to ' . APPNAME . '</h2>'; $output .= '<div class="field">';

我正在通过PHP函数显示一个表单:

function getLoginForm($errors = false) {
    $output .= '<form action="#" name="login" method="post" />';
        $output .= '<h2>Sign in to ' . APPNAME . '</h2>';
        $output .= '<div class="field">';
            $output .= '<label for="username">Username</label>';
            $output .= '<input type="text" id="username" name="username"' . getPostValue('username')  . ' />';
            if(isset($errors['username'])) {
                $output .= '<div class="help">' . $errors['username'] . '</div>';
            }
        $output .= '</div>';
        $output .= '<div class="field">';
            $output .= '<label for="password">Password</label>';
            $output .= '<input type="password" id="password" name="password"' . getPostValue('password')  . ' />';
            if(isset($errors['passsword'])) {
                $output .= '<div class="help">' . $errors['username'] . '</div>';
            }
        $output .= '</div>';
        $output .= '<div class="message"></div>';
        $output .= '<div class="button">';
            $output .= '<button type="button" name="commit">Login</button>';
        $output .= '</div>';
    $output .= '</form>';
    return $output;
}
尝试使用“live()”绑定到动态创建的对象的事件

为此,您需要将代码更改为:

$('form').live('submit', function() { ...

使用“live”绑定到事件将绑定到与jQuery选择器匹配的所有当前和未来元素。由于您正在覆盖表单,这是一个新元素,因此您当前的代码将不会绑定到提交事件。

请共享您的jQuery表单提交处理程序或单击处理程序。显示原始表单html
live()
已被弃用,最好使用
delegate()
或,如果您使用的jQuery 1.7+
on()
不起作用,因为一旦将表单替换为包含错误的新表单,该表单就不会被绑定。如果我不得不猜测,我是否需要在$('form').submit()函数中添加一些内容,以便在获取新表单后绑定它?
$('form').live('submit', function() { ...