My form onSubmit
is calling:
onsubmit="validate(this); return false;"
validate();
is as follows:
function validate(obj) {
$.ajax({
url : "ajax/validate_check.php",
type : "POST",
data : $("#" + obj.id).serialize(),
success : function(data) {
$('#' + obj.id + ' :input.form_errors').removeClass('form_errors')
data = $.parseJSON(data);
if(data['error_count'] >= 1) {
$.each(data, function(i, item) {
$('#' + i).addClass('form_errors');
});
} else {
$('#' + obj.id).submit();
}
}
});
}
When I have 0
errors it's trying to submit the form but I'm getting an infinite loop. I realize it's happening because my onSubmit
calls the function again. How do I actually submit the form when I'm ready?
EDIT:
I'm just looking for the best way to approach this. I want to validate onSubmit
for a quick response to the user and then I want to actually submit the form that way I know where the data is going (eg register.php will register a user).
That's why I'm not doing a combined action/validate script because I wouldn't know which form I'm submitting. I probably need to rearrange the way I'm doing this.