-
-
Save larbous/fb1ac33e42b7847486cf690b53272b6c 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
<script> | |
(function(document){ | |
function populateForms(){ | |
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.querySelectorAll('*[name^="mauticform[' + key + ']"'); | |
inputs.forEach(function (input) { | |
if(input.type==='checkbox' && input.value===value){ | |
input.checked=1; | |
} else { | |
input.value = value; | |
} | |
}); | |
} | |
}); | |
} | |
} | |
} | |
document.addEventListener('readystatechange',populateForms); | |
populateForms(); | |
}(document)); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment