var captchaValid = false; var errormessage = "An error has occurred. Please refresh your browser. If the problem continues contact us." var successmessage = "Thank you for your enquiry" var invalidEmail = "Email - Invalid" var capchaError = "I am not a robot" $('form').submit(function(e) { if ($("#successtext").val()){ successmessage = $("#successtext").val(); }; var successHTML = '
' var errorHTML = ' ' $("#serverresponse").hide(); //$("#serverresponse").removeClass("form_errors") e.preventDefault(); //alert($("#terms").) var valid = validateSubmitForm(); if (valid) { dataLayer.push({ 'formType': 'api_contact_form', 'event': 'formSubmission' }); var formData = new FormData(this); var submiturl = $(this).attr("action") $.ajax({ url: '/sites/Satellite', type: 'POST', data: formData, contentType: false, processData: false, error:function(jqXHR, textStatus, errorThrown) { //$("#serverresponse").addClass("form_errors"); $("#serverresponse").html(errorHTML); $("#serverresponse").show(); grecaptcha.reset(); captchaValid = false; $('html, body').animate({scrollTop: $("section").offset().top}, 750); }, success: function (data) { grecaptcha.reset(); captchaValid = false; if (submiturl && submiturl !='#' ){ reset(); resetSelect(); window.location= submiturl; }else{ //$("#serverresponse").removeClass("form_errors") $("#serverresponse").html(successHTML); $("#serverresponse").show(); $('html, body').animate({scrollTop: $("section").offset().top}, 750); reset(); resetSelect(); } } }); }else{ $('html, body').animate({scrollTop: $("section").offset().top}, 750); } }); function reset(){ $('form').find("input[type=text], textarea, input[type=email]").val(""); } function captchaClicked() { captchaValid = true; } function captchaInvalidated() { captchaValid = false; } function validateSubmitForm() { var errorList =""; $("#errordetails").hide(); $("#errordetails ul").html(""); $("#registrationform :input").each(function() { $(this).removeClass("submit--error"); var isrequired = $(this).attr('data-required') if (isrequired==='true'){ var validmailcheck = $(this).attr('data-emailid') var Elmentid= $(this).attr('id') if ($(this).val() === ""){ var title = $(this).attr('title') $(this).addClass("submit--error"); var errorMessage = "