0

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>
4

2 回答 2

0

您必须将loginform表单标签设置为 id 属性。当您$('#loginform')用作选择器时。

于 2013-08-05T19:15:06.727 回答
0

您的 JS 中有语法错误。您不需要将 formhash 函数包装在大括号中。试试这个:

$("#login_form").validate({
    submitHandler: function formhash(form, password) {
        //submit code
    }
});
于 2013-08-05T20:45:29.467 回答