3

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?

3
  • Are you getting any errors in your console log? Commented Jan 26, 2013 at 13:41
  • No, not showing any error in cosole log. even if i give any URL in form action it's not going out there too. Commented Jan 26, 2013 at 13:42
  • everything looking fine .sorry .i too spent 15 min . Commented Jan 26, 2013 at 13:52

1 Answer 1

5

Set debug to false:

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.