为什么我的表单提交并忽略验证?

时间:2016-04-30 10:09:53

标签: javascript jquery forms validation

我想弄清楚为什么jquery validation不会阻止我的表单被提交?当按下提交按钮时,表单正确发布,但似乎忽略了验证错误(此字段是必需的),即使输入字段留空。

表格

$(document).ready(function() {
  $("#message").hide();

  //Define your validation rules.
  $(function() {
    $("#myform").validate({

    });
    $("#submitButtonId").on("click", function(e) {
      var formdata = $("#myform").serialize();
      //Post form data
      $.post('php_includes/simple_insert.php', formdata, function(data) {
        //Process post response
        $("#message").html(data);
        $("#message").fadeIn(500);
        $("#message").fadeOut(500);
      });

      //Reset Form
      $('#myform')[0].reset();
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.0/jquery.validate.min.js"></script>

<form class="form-inline" action="" id="myform" method="post">

  <!-- Text input-->
  <div class="form-group">
    <label class="col-md-4 control-label" for="bill_cost"></label>
    <div class="col-md-8">
      <input id="bill_cost" name="bill_cost" type="text" placeholder="Bill Cost" class="form-control input-lg" required>

    </div>
  </div>

  <!-- Button -->
  <div class="form-group">
    <label class="col-md-4 control-label" for="submit1"></label>
    <div class="col-md-4">
      <button type="submit" id="submitButtonId" name="submit1" class="btn btn-primary btn-xl">Submit</button>
    </div>
  </div>
</form>

2 个答案:

答案 0 :(得分:3)

试试这个,使用submitHandler为有效表单做其他事情:

Unhandled rejection AssertionError: expected {
  message: 'column Invoice. is_processing does not exist',
  name: 'SequelizeDatabaseError',
  original: {
  [error: column Invoice.is_processing does not exist]
....

答案 1 :(得分:-1)

在帐单费用文本框中删除必需标记。然后检查验证是否被忽略