$(document).ready(function() { $('.SubmitForm').bind('click',function() { if (checkRequired($(this))) { SubmitForm($(this)); } }); }); function enableBtn(e) { //console.log(e); $('#g-response').val(e); $('.SubmitForm').removeAttr('disabled'); $('.SubmitForm').removeClass('disabled'); }; function disableBtn(e) { $('.SubmitForm').addClass('disabled'); $('.SubmitForm').attr('disabled','disabled'); }; function checkRequired(x) { var result = true; var parent = x.closest('.form-wrapper'); var fields = $(parent).find('select, textarea, input'); $(fields).each(function() { $(this).removeClass('empty'); if ($(this).hasClass('required') && !$(this).val()) { $(this).addClass('empty'); result = false; $(parent).find('.submitFormMessage').html('You must enter all required fields'); } }); return result; } function SubmitForm(x) { var parent = x.closest('.form-wrapper'); //console.log(parent); //console.log($('#g-response').val()); $(parent).find('.SubmitForm').addClass('disabled'); $(parent).find('.SubmitForm').attr('disabled','disabled'); $(document.body).css({'cursor' : 'wait'}); setTimeout( function(){ $(document.body).css({'cursor' : 'default'}); }, 1500); var vals = $(parent).find('select, textarea, input').serialize(); $.ajax({ type: 'POST', crossDomain: true, url: 'https://www.firehorse-cms.com/Components/Form/Assets/AJAX/SubmitForm.php', dataType : 'text', // data type data : vals, error: function(msg){ grecaptcha.reset(); }, success: function(msg){ console.log(msg); var ret = msg.split(':'); if (ret[0] == 1) { $(parent).find('.AfterText').fadeIn(); $(parent).find('.FormText').fadeOut(); } else { grecaptcha.reset(); $(parent).find('.submitFormMessage').html('
'+ret[1]+'
'); setTimeout(function() { $(parent).find('.submitFormMessage').html(''); }, 13000); } } }); }