I have a page with multiple forms on it. Each form has it’s own Save button which validates and displays error messages using .ajax() to post (not a normal post method). I also have a Next button outside of the forms which is caught by jQuery click() handler. This function goes through each form and calls $(formname).submit() for each.
Ultimately I need to know if the individual forms passed validation in order to determine if a redirect should happen. I have added, return false; in the else statement of the validate check in the submit function but I cannot see how to retrieve it.
Having alert($(this).submit()); just returns the object not a return value. Without re-coding the whole $.ajax post code for each form, is there anyway I can find out if the submit failed??
//next button click
$('#savenext').click(function () {
var finalsuccess;
$('.record_form').each(function (index) {
alert($(this).submit()); //I want this to be true or false
});
//forms each have their own submit handler
$(formname).submit(function (e) {
e.preventDefault();
var form = $(this);
if($(form).valid()) { //validate the form, return false if it is not valid.
//Post the form to the action if it passes
$.ajax({
url: form.attr('action'),
type: "POST",
dataType: "text json",
data: form.serialize(),
success: function (response) {
//does some success messages here
},
});
}
else {
return false;
}
});
Thanks
In case anyone needs to know, I found no way to get the submit to return a success value. In the end I changed the ajax post to be async: false, put that in a function which returned a boolean set by either the success or error event of the ajax post. Not as quick because of the succession of server calls but I will add a loading dialog to help with that.