Skip to content

Instantly share code, notes, and snippets.

@jtsternberg
Created September 30, 2021 14:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jtsternberg/f9a17ca2feebb510cf3d830aa5086e6e to your computer and use it in GitHub Desktop.
Autopopulate OM optin fields from query params
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