Skip to content

Instantly share code, notes, and snippets.

@RobertCalise
Created June 13, 2017 17:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertCalise/87ec77e5acd63545ebba9463453d181b to your computer and use it in GitHub Desktop.
Save RobertCalise/87ec77e5acd63545ebba9463453d181b to your computer and use it in GitHub Desktop.
Grab a URL parameter (hop) and insert it into an Infusionsoft web form hidden field

The Javascript in this gist can be used to grab a parameter (in this example, called "hop") from the URL's query string and place that value into a hidden form field (in this example, with an id of #inf_field_FieldName.)

There are two assumptions in this example, so you should alter them for your own use case.

Assumption 1: the URL parameter you're getting is called "hop".

For example, if you are accessing this page at http://example.com/?hop=something, then this example would retrieve a value of "something". If your URL parameter is called something other than "hop", change it on Line 8 of the example script from

document.getElementById('inf_field_FieldName').value = getUrlParameter('hop');

to

document.getElementById('inf_field_FieldName').value = getUrlParameter('otherparameter');

Assumption 2: the Infusionsoft hidden field you're using is called "FieldName".

In reality, this will be whichever field you're trying to populate. So, for example, if you're trying to populate a First Name field, that ID would be "inf_field_FirstName". So you would modify Line 8 of the example script from

document.getElementById('inf_field_FieldName').value = getUrlParameter('hop');

to

document.getElementById('inf_field_FirstName').value = getUrlParameter('hop');

<script type="text/javascript">
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
document.getElementById('inf_field_FieldName').value = getUrlParameter('hop');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment