Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Last active January 24, 2018 17:00
Show Gist options
  • Save ChrisLTD/6aeb648622bec3dd5468985b527926ae to your computer and use it in GitHub Desktop.
Save ChrisLTD/6aeb648622bec3dd5468985b527926ae to your computer and use it in GitHub Desktop.
// Creates iframe to submit lead data to pardot
// @paramList should be in the format param1=something&param2=somethingelse
function submitPardotLead(formHandlerUrl = '//localhost/no-valid-form-handler-url',
paramList = 'noparams=provided',
callbackFn = function() {}) {
// build URL
var srcUrl = formHandlerUrl + '?' + paramList;
// create iframe el
const bodyEl = document.querySelector('body');
var iframeEl = document.createElement('iframe');
iframeEl.setAttribute('src', srcUrl);
iframeEl.setAttribute('class', 'pardot-form-handler');
iframeEl.setAttribute('width', '0');
iframeEl.setAttribute('height', '0');
iframeEl.setAttribute('style', 'width: 0px; height: 0px; display: none !important;');
// once the iframe is loaded, fire the callback
iframeEl.addEventListener('load', function(){
callbackFn();
});
// appending it with the proper src tag is the same as submitting the form
bodyEl.appendChild(iframeEl);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment