Skip to content

Instantly share code, notes, and snippets.

@cbarley10
Last active February 19, 2020 15:57
Show Gist options
  • Save cbarley10/7c78ce1205858002df3276ac12c48db2 to your computer and use it in GitHub Desktop.
Save cbarley10/7c78ce1205858002df3276ac12c48db2 to your computer and use it in GitHub Desktop.
<script>
document.addEventListener("DOMContentLoaded", function() {
$("button[type='submit']").click(function(e) {
if ($("#subscribeToNewsletter").is(':checked')) {
e.preventDefault();
// grab fields
var email = $('input#shippingEmail').val();
var firstname = $('input#shippingFirstName').val();
var company = $('#shippingCompanyName').val() || "";
var lastname = $('input#shippingLastName').val();
var address = $('input#shippingAddressOne').val();
var address2 = $('input#shippingAddressTwo').val();
var city = $('input#shippingAddressCity').val();
var state = $('#shippingState').val();
var zip = $('#shippingZipCode').val();
var settings = {
"async": true,
"crossDomain": true,
"url": "https://manage.kmail-lists.com/ajax/subscriptions/subscribe",
"method": "POST",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"cache-control": "no-cache"
},
"data": {
"g": "LIST_ID",
"email": email,
// pass in additional fields
"$fields": "$source, $first_name, $last_name $address1 $address2 $city $region $zip $organization",
"$source": "Checkout Page",
"$first_name": firstname,
"$last_name": lastname.
"$address1": address,
"$address2": address2,
"$city": city,
"$region": state,
"$zip": zip,
"$organization": company
}
};
$.ajax(settings).done(function(response) {
console.log(response);
// select and submit form after subscribing
$("#dwfrm_shipping").submit();
})
}
})
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment