Created
September 30, 2021 14:17
Star
You must be signed in to star a gist
Autopopulate OM optin fields from query params
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
document.addEventListener('om.Form.init', function(evt) { | |
console.log('om.Form.init') | |
var Form = evt.detail.Form; | |
var getQueryParam = function( param ) { | |
if (!getQueryParam.params) { | |
getQueryParam.params = {}; | |
var query = window.location.search.substring(1); | |
var parts = query ? query.split('&').map(s => s.split('=')) : [] | |
parts.forEach(part => { | |
getQueryParam.params[part[0]] = part[1] | |
}) | |
} | |
return getQueryParam.params[param] | |
} | |
setTimeout(() => { | |
Form.inputs.forEach(function(input) { | |
var inputName = input.name.replace(Form.C.ns, '').replace('-', ''); | |
if ('name' === inputName) { | |
input.value = getQueryParam('form_first_name') + ' ' + getQueryParam('form_last_name'); | |
} else if ( getQueryParam('form_' + inputName) ) { | |
input.value = getQueryParam('form_' + inputName); | |
} | |
}); | |
}, 10); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment