Skip to content

Instantly share code, notes, and snippets.

@acoyfellow
Last active May 9, 2020 14:13
Show Gist options
  • Save acoyfellow/3058e1b09a5ff2667628357f33623dfb to your computer and use it in GitHub Desktop.
Save acoyfellow/3058e1b09a5ff2667628357f33623dfb to your computer and use it in GitHub Desktop.
Email must be pre-populated (from InfusionSoft server-side, or via url search parameters). Also store affiliate into cookies if it's there.
<script>
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}else{
expires = "";
};
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
};
jQuery(document).ready(function () {
var inf_contact_key = getParameterByName('inf_contact_key');
var inf_field_Email = getParameterByName('inf_field_Email');
var firstName= jQuery('#firstName');
var emailAddress= jQuery('#emailAddress');
var purchaseButton= jQuery('.complete-purchase');
if (inf_contact_key) {
// lock down fields since InfusionSoft pre-populates.
if (firstName.val()!=='') {
firstName.prop('disabled', true);
};
if (emailAddress.val()!=='') {
emailAddress.prop('disabled', true);
}else{
//edge case: infusionsoft does not have email injected
//
};
}else if(inf_field_Email){
emailAddress.val(inf_field_Email);
emailAddress.prop('disabled', true);
}else{
// No email or infusionsoft data found in URL.
// Possibly done via cookies + server side render
if (emailAddress.val()!==''){
emailAddress.prop('disabled', true);
}else{
//Re-direct back to dashboard = off
};
};
var params= window.location.search;
jQuery("a[href='https://ee289.infusionsoft.com/app/orderForms/f0791acc-a9e8-4796-8bad-d6eae1acca8f']")
.attr('href', 'https://ee289.infusionsoft.com/app/orderForms/f0791acc-a9e8-4796-8bad-d6eae1acca8f'+params);
jQuery("a[href='https://ee289.infusionsoft.com/app/orderForms/e1da5d9f-8731-479a-80ab-dd714abb66e0']")
.attr('href', 'https://ee289.infusionsoft.com/app/orderForms/e1da5d9f-8731-479a-80ab-dd714abb66e0'+params);
//if affiliate in url, set to cookies
var affiliate = getParameterByName('affiliate');
if(affiliate){
createCookie('affiliate', affiliate, 30);
};
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment