Last active
November 5, 2022 21:57
-
-
Save patrickfreitasdev/cc3d6569c670ad3559e31f58fbaec754 to your computer and use it in GitHub Desktop.
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
<?php | |
add_action( 'wp_footer', function(){ ?> | |
<script> | |
(function ($) { | |
$(function () { | |
$(document).on("after.load.forminator", function (e, id) { | |
function getQueryParams(qs) { | |
qs = qs.split("+").join(" "); | |
var params = {}, tokens, re = /[?&]?([^=]+)=([^&]*)/g; | |
while (tokens = re.exec(qs)) { | |
params[decodeURIComponent(tokens[1])] = decodeURIComponent(tokens[2]); | |
} | |
return params; | |
} | |
var query_params = getQueryParams(document.location.search); | |
// Update the hidden-ID to match the correct fields | |
$(`forminator-custom-form #hidden-1`).val( query_params['utm_source'] ); | |
$(`forminator-custom-form #hidden-2`).val( query_params['utm_medium'] ); | |
$(`forminator-custom-form #hidden-3`).val( query_params['utm_campaign'] ); | |
$(`forminator-custom-form #hidden-4`).val( query_params['utm_content'] ); | |
$(`forminator-custom-form #hidden-5`).val( query_params['utm_term'] ); | |
$(`forminator-custom-form #hidden-6`).val( query_params['gclid'] ); | |
}); | |
}); | |
})(window.jQuery); | |
</script> | |
<?php }, 21); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment