$(document).on('keypress', '.empty_error', function(){ $(this).removeClass('empty_error'); }); $('.f_submit').click(function(){ var regBlank = /[^\s]/; var regemail = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/; var i = 0; $(".required").each(function(e) { vl = $(this).val(); if(!regBlank.test(vl)){ $(this).addClass('empty_error'); i++; }else{ //alert($(this).attr("name") + ' = ' + vl); } if($(this).attr('type')=='email'){ if(!regemail.test(vl)){ $(this).addClass('empty_error'); i++; } } }); if(i==0){ var formData_arr = $("#myForm").serializeArray() formData_arr[formData_arr.length] = { name: "action_model", value: "action" }; formData_arr[formData_arr.length] = { name: "action_method", value: "post_contact" }; var formData = JSON.stringify(formData_arr); var btn = $(this); btn.prop( "disabled", true ); $('#f_reply').prepend('
') $.ajax({ type: 'post', url: URL + 'submit-request', data: formData, dataType: "json", contentType : "application/json", success: function (response) { //const obj = JSON.parse(response); obj = response; btn.removeAttr('disabled'); if(obj.error==1){ $('.msg').prepend(obj.msg); $('.msg').html(obj.msg); $(".msg" ).fadeIn( 300 ).delay( 2500 ).fadeOut( 400 ); } if(obj.error==0){ $('#f_reply').html(obj.msg); } } }); } })