Last active
April 15, 2020 16:39
-
-
Save shawncarr/56c2484cb50bc923107f210310366ad0 to your computer and use it in GitHub Desktop.
Pre-populate Mautic Form Data from Query String Parameters
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.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; | |
}); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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 :)