Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does submit get called if form is invalid?

I want to know if submit gets called if my form data are not valid in html5 validation. For example I have a form id personal_info.

I use the following block to get on submit event :

$("#personal_info").submit(function(event) {

    event.preventDefault();
    saveData("personal_info");
});
function saveData(formName){
 console.log("test");
}

Is is the default behavior that the function saveData gets called on submit because even if my form is not valid the function gets called.

How to prevent submit function from being called if my form is invalid?

like image 956
user2327579 Avatar asked Oct 18 '25 05:10

user2327579


1 Answers

The new HTML5 validation APIs will not submit an invalid form unless you use the novalidation attribute on the form. See https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Data_form_validation for more information.

like image 74
Jacob Wright Avatar answered Oct 20 '25 18:10

Jacob Wright



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!