表单永远不会使用jQuery验证插件提交-即使有效 [英] Form never submits using jQuery validation plugin - even when valid

查看:90
本文介绍了表单永远不会使用jQuery验证插件提交-即使有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery验证插件来验证我的表单,但是即使成功验证后,该表单也不会提交.这是重现此问题的代码:

I am using a jQuery Validation plugin to validate my form, but the form does not submit even after successful validation. Here is code to reproduce the issue:

<?php
if(isset($_REQUEST['submit'])){
    echo "form submitted";  //have to insert into database here
}
?>

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>
<script type="text/javascript">
jQuery.validator.setDefaults({
    debug: true,
    success: "valid"
});;
</script>
<script>
  $(document).ready(function(){
    $("#myform").validate({
  rules: {
    field1: {
      required: true,
      number: true
    },
    field2: {
      required: true,
      number: true,
      minlength: 3
    },
    field3: {
      required: true,
      email: true
    }
  }
});
  });
  </script>


    <form id="myform" method="post" action="">
      <div>
        <label for="field">Required, decimal number: </label>
        <input class="left" id="field1" name="field1" type="text" />
      </div>
      <br>
      <div>
        <label for="field">Required, Minimum length 3: </label>
        <input class="left" id="field2" name="field2" type="text" />
      </div>
      <br>
      <div>
        <label for="field">Required, email: </label>
        <input class="left" id="field3" name="field3" type="text" />
      </div>
      <br/>
      <input type="submit" name="submit" value="Validate!" />
    </form>

请注意,无论是否在表单标签中执行有效操作,都会发生这种情况.

Note, this happens with or without a valid action in the form tag.

这可能是什么原因造成的?

What could be causing this?

推荐答案

debug设置为false:

<script type="text/javascript">
jQuery.validator.setDefaults({
    debug: false,
    success: "valid"
});;
</script>

如果debug为true,则不提交表单: http://docs .jquery.com/Plugins/Validation/validate#options 例如. http://codepad.viper-7.com/H4OFP5

If debug is true, the form is not submitted: http://docs.jquery.com/Plugins/Validation/validate#options E.g. http://codepad.viper-7.com/H4OFP5

这篇关于表单永远不会使用jQuery验证插件提交-即使有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆