Skip to content

Instantly share code, notes, and snippets.

@shawncarr
Last active April 15, 2020 16:39
Show Gist options
  • Save shawncarr/56c2484cb50bc923107f210310366ad0 to your computer and use it in GitHub Desktop.
Save shawncarr/56c2484cb50bc923107f210310366ad0 to your computer and use it in GitHub Desktop.
Pre-populate Mautic Form Data from Query String Parameters
document.onreadystatechange = function () {
if (document.readyState == 'interactive') {
if (document.forms.length !== 0 && location.search) {
var query = location.search.substr(1);
query.split('&').forEach(function (part) {
if (part.indexOf('=') !== -1) {
var item = part.split('=');
var key = item[0];
var value = decodeURIComponent(item[1]);
var inputs = document.getElementsByName('mauticform[' + key + ']');
inputs.forEach(function (input) {
input.value = value;
});
}
});
}
}
}
@stevedrobinson
Copy link

@shawncarr I forked your script to work if run after the form loads and to handle checkboxes: https://gist.github.com/stevedrobinson/66aa33f3f26ee81e80ae49fd89390713

Thought you might like to update yours, since I'm not sure how to do PRs on gists :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment