如果我有一个 html 表单验证工作
<form method="POST" action="" name="loginForm" id="loginForm">
<p><input type="text" name="user" id="user" "/></p>
<div class="formInputMistake" id="errorEmail"></div>
<p><input type="password" name="passwd" id="passwd" /></p>
<div class="formInputMistake"></div>
<input type="submit" name="login" id="login" value="Login" />
<div class="formInputMistake"></div><!--here i want to show error "wrong password or user"-->
</form>
php 文件 usr.php
if(isset($_GET['login']) && isset($_POST['user']) &&
isset($_POST['passwd']) && isset($_POST['login'])) {
if($_POST['user'] = "admin" && $_POST['passwd'] == "admin") {
//successful log in
$_SESSION['user'] = $_POST['user'];
$_SESSION['passwd'] = $_POST['passwd'];
echo 'true';
} else {
echo 'false';
}
}
还有一个 jQuery 代码,使用validate-plugin
Jörn Zaefferer 制作的
$(document).ready(function(){
$("#loginForm").validate({
ignore: ".ignore",
rules: { email: {...}, loginPasswd: {...} },
messages: { email: {...}, loginPasswd: {...} },
submitHandler: function(form) {
$.post('usr.php?login', $(form).serialize(), function (data, textStatus) {
if(data == 'true') {
$('#loginForm').hide();
} else if(data == 'false') {
//Last formInputMistake - showing the "wrong password or user"??
}
});
}
});
});
如何验证来自服务器的错误?
谢谢