Skip to content

Instantly share code, notes, and snippets.

@mabumusa1
Created December 3, 2017 12:19
Show Gist options
  • Save mabumusa1/fc353b0626568221088bb43e7fb453e8 to your computer and use it in GitHub Desktop.
Save mabumusa1/fc353b0626568221088bb43e7fb453e8 to your computer and use it in GitHub Desktop.
function getParameterByName(name) {
var url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
$( "input[name*='mauticform'][type='hidden']" ).each(function(index){
var itemName = $(this).attr('name').match(/\[(.*?)\]/)[1];
var utms = ["gclid", "utm_source", "utm_medium", "utm_campaign", "utm_content", "utm_term"];
if($.inArray(itemName, utms) !== -1){
var elementName = "input[name='mauticform["+ itemName +"]]";
$(elementName).val(getParameterByName(itemName))
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment