jQuery(document).ready(function(){ //Find all forms on the page with the class mgl-proxy jQuery("form.mgl-proxy").each(function(){ //Watch the submit event and instead post it to the proxy script via Ajax jQuery(this).submit(function(e){ e.preventDefault(); if (jQuery("[name='PatronEmail']", this).val() == "" || jQuery("[name='PatronEmail']", this).val().indexOf("@") < 1) { alert("Please enter a valid email address"); return; } //Mark the submit button as disabled jQuery("[type='submit']", this).attr("disabled", "disabled"); var form = this; //Send the form jQuery.post("https://philhawthorne.com/wp-content/plugins/mgl-form/proxy.php", jQuery(this).serialize(), function(result){ if (result.dbl_optin) { alert("Please check your email inbox"); if (typeof ga == "function") ga('send', 'event', "form", "Email Subscription"); } else { alert("Thank You"); } jQuery("[type='submit']", form).removeAttr("disabled"); }, "json"); }); }); });