-
-
Save stevedrobinson/66aa33f3f26ee81e80ae49fd89390713 to your computer and use it in GitHub Desktop.
Pre-populate Mautic Form Data from Query String Parameters
This file contains hidden or 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
(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)); |
Hi. I have read the threads on this and would love to try out this patch. I am not a developer. I can find my way around code but have no idea where I should put this file. Could you let me know.
Thanks
Well, Though late, it may be useful....
One Option is You should add this file in the theme folder...
- Create a file
/themes/<your_landingpage_theme_folder>/js/mautic-form-preload.js
- Edit File
/themes/<your_landingpage_theme_folder>/html/base.html.twig
<HTML>
<head>
....
</head>
<body>
.......
</body>
<script type="text/javascript" src="{{ getAssetUrl('themes/'~template~'/js/mautic-form-preload.js')}}"></script>
</html>
- Voila! Start populating your Pages & Forms
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I have read the threads on this and would love to try out this patch. I am not a developer. I can find my way around code but have no idea where I should put this file. Could you let me know.
Thanks