jQuery Validate 正在工作(当所需的电子邮件字段为空时触发错误),但 submitHandler 中的代码未触发(不显示警报)。而且由于 submitHandler 不起作用,我不希望表单发布到 secure/process_login.php,因为 form.submit(); 在不工作的 alert() 之后,但如果它验证它就会这样做。
表格代码:
<form action="secure/process_login.php" method="post" id="login_form" name="login_form">
<fieldset>
<legend>Log In</legend>
<div class="form-group">
<label for="inputEmail">Email address</label>
<input type="text" id="email" class="form-control" name="email"placeholder="Your Email Address" required>
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
<input type="password" class="form-control" name="password" id="password" placeholder="Your Password">
<input type="hidden" name="p" id="p" value="">
</div>
<button type="submit" class="btn btn-primary form-control">Log In</button>
</fieldset>
</form>
脚本:
<script>
$("#login_form").validate({
submitHandler: {
function formhash(form, password) {
// Create a new element input, this will be out hashed password field.
var p = document.createElement("input");
// Add the new element to our form.
form.appendChild(p);
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
alert("Test");
form.submit();
}
}
});
</script>