Validate form with jQuery on submit -
i have function when click on 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 call validate methods on blur events on fields, , work , validation here seems work, problem after if statement nothing happens, form isn't submitted. have idea why? , if not can think of better way validate fields before submit?
the problem variables use in if statement returning undefined screwed call. replaced checking variables checking set classes on dom elements see if have errors , worked fine.
Comments
Post a Comment