jQuery('body').on('click','.leadbox-submit', function(e) { e.preventDefault(); var leadboxForm = jQuery(this).closest('form'); var recaptchaBox = leadboxForm.find('.g-recaptcha-response'); var postedValues = {}; leadboxForm.find("input, select").each(function(i, v) { postedValues[jQuery(v).attr('name')] = jQuery(v).val(); }); postedValues['g-recaptcha-response'] = recaptchaBox.val(); var postdata = { 'action': 'APWTLeadBox', 'apwtleadbox': 'submit', 'apwtvalues': postedValues }; jQuery.ajax({ type : "post", dataType : "json", url : APWTajaxurl.ajaxurl, data : postdata, success: function(response) { if(response.status == "error") { leadboxForm.find('.leadbox-error').html(response.message); grecaptcha.reset() //reset recaptcha } else { if (response.status != 'paige') { if (response.status == 'url') { window.location.href = response.message; } else { leadboxForm.html(thanksMessage); } } } } }); });