Last active
May 21, 2023 15:31
-
-
Save repentsinner/d9ac8e81a7f8804a370ff52f6fc6d896 to your computer and use it in GitHub Desktop.
Webflow ActiveCampaign Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set an id of 'subscribe' on the form element in Webflow | |
// add an embedded object that contains hidden inputs with the same data | |
// that ActiveCampaign generates from their form builder | |
document.getElementById('subscribe').onsubmit = function (event) { | |
try { | |
// hide previous errors | |
this.closest('.w-form').querySelector('.w-form-fail').style.display = 'none'; | |
// jsonp nastiness to account for an inability to configure CORS origins in activecampaign 😠 | |
// the script that is loaded will call window._show_thank_you() and window._show_error() | |
let s = document.createElement("script"); | |
let sp = new URLSearchParams(new FormData(this)); | |
s.src = "https://doequalsglory.activehosted.com/proc.php?jsonp=true&" + sp.toString(); | |
document.body.appendChild(s); | |
} catch (err) { | |
} | |
// prevent propagation to Webflow default submission behavior | |
event.stopPropagation(); | |
return false; | |
} | |
window._show_thank_you = function (id, message, trackcmp_url) { | |
// find form with hidden element with u=id | |
try { | |
// show thank you | |
document.querySelector("input[value='" + id + "']").closest('.w-form').querySelector('.w-form-done').style.display = 'inherit'; | |
// hide form | |
document.querySelector("input[value='" + id + "']").form.style.display = 'none'; | |
} catch (err) { | |
} | |
}; | |
window._show_error = function (id, message, html) { | |
// find form with hidden element with u=id | |
try { | |
// show error | |
let msg = document.querySelector("input[value='" + id + "']").closest('.w-form').querySelector('.w-form-fail'); | |
msg.innerHTML = message; | |
msg.style.display = 'inherit'; | |
} catch (err) { | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment