Skip to content Skip to sidebar Skip to footer

How To Prevent Form Submission In Case Of Valiadtion Error With Standard Form Submission?

I am developing a form that which includes some textfields and some fields for file uploads. Some javascript code builds the form dynammically by adding it to to a div element (id=

Solution 1:

Quote OP:

"I want to have the textfields validated by means of jquery validate"

Since you're using the jQuery Validate plugin, simply implement the submitHandler callback for your ajax. As per documentation, this is "the right place to submit a form via Ajax after it is validated".

Despite others' answers,

  • You do not need inline JavaScript.

  • You do not need any additional event handlers.


var completeform = $("#formNewAgreements");
completeform.validate({
    submitHandler: function(form) {
        // your ajax here
        return false;  // block default form action
    }
});

DEMO: http://jsfiddle.net/U4P3F/


Solution 2:

Try this

<input type="submit" name="submitForm" value="Confirm" onclick='completeform.validate();' />

In this case your validate method should return true or false depending on if form is valid or not.

EDIT: As @lex82 mentioned the proper way to do this is to add handler to form submit. Change you form tag to:

<form id="formNewAgreements" name="formNewAgreements" action="submit_x1.php" method="post" enctype="multipart/form-data" target="hidden-form" onsubmit='completeform.validate();'>

Post a Comment for "How To Prevent Form Submission In Case Of Valiadtion Error With Standard Form Submission?"