To capture specific individual parameter values from the URL query string and insert into multiple corresponding hidden fields:
- Make sure you have created the custom fields that you would like to use as HIDDEN form fields to receive the query string data.
- To pull out individual parameter values, use the guppy() function:
function guppy(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
} - To get parameter values, just pass in the parameter name.
var paramvalue = guppy('PARAM_NAME');
- You can set values of a hidden input like so:
document.getElementById('UDF_ID').value = guppy('PARAM_NAME');
...where UDF_ID is the ID of the UDF to populate with data and “PARAM_NAME” is the name of the parameter you want a value for, for each UDF/parameter pair.
- Complete code will look similar to this:
Hidden fields in form:<input name="x_udf_leadsource79" id="x_udf_leadsource79" type="hidden" />
<input name="x_udf_utmsource80" id="x_udf_utmsource80" type="hidden" />
<input name="x_udf_utmmedium81" id="x_udf_utmmedium81" type="hidden" />
<input name="x_udf_utmcampaign82" id="x_udf_utmcampaign82" type="hidden" />
Script at end of page that populates fields with query string data:
<script type="text/javascript">
function guppy(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
document.getElementById('x_udf_leadsource79').value = window.location.href.substr(window.location.href.indexOf('?') + 1);
document.getElementById('x_udf_utmsource80').value = guppy('utm_source');
document.getElementById('x_udf_utmmedium81').value = guppy('utm_medium');
document.getElementById('x_udf_utmcampaign82').value = guppy('utm_campaign');
</script> - Data in eTrigue record will look like this:
To learn how to capture an entire URL query string and insert it into a SINGLE hidden field in a form, click here.