I have this function when I click on my submit button:
$('#signup-button').click(function(event){
var username_check = validateUsernameField();
var email_check = validateEmailField();
var name_check = validateNameField();
var birthdate_check = validateBirthdateField();
event.preventDefault();
if(username_check && email_check && name_check && birthdate_check) {
alert('lol');
var formData = $('#FonykerAddForm').serialize();
$.ajax ({
type: 'POST',
url: '<?php echo $html->url('/fonykers/add',true); ?>',
data: formData,
dataType: 'json',
success: function(response) {
$( "#confirm-dialog" ).html(response.msg).dialog({
autoOpen: false,
modal: true,
height: 140,
title: response.title
});
$('#confirm-dialog').dialog('open');
},
error: function (xhr, ajaxOptions, thrownError){
alert('Cualquier vaina');
alert(xhr.statusText);
alert(thrownError);
}
});
}
});
I previously call the validate methods on blur events on my fields, and they all work and the validation here seems to work, the problem is that after the if statement nothing happens, the form isn’t submitted. Anybody have any idea why? And if not can you think of a better way to validate all my fields before submit?
The problem was the variables I use in the if statement some were returning undefined so it screwed up the call. I simply replaced checking for the variables to checking for set classes on my DOM elements to see if they have errors and it worked fine.