Skip to main content

Is it possible to get a value from the URL and change it to another value in a hidden field?


Example campaign URL with a Unbounce form: www.mydomain.dk?source=345

The URL variable ‘source=345’ correspondence with an ID variable (ex. ‘Ef45RfghtTY67HFD’) in another system which I’m sending data to trough a webhook.


So when I recieve the varible ‘source=345’ from the URL in my Unbounce form I need it to change that value to ‘Ef45RfghtTY67HFD’ and place than value to a hidden field called ‘leadsource_id’ before it get send through the webhook.


Ex.

source=345 -> leadsource_id=Ef45RfghtTY67HFD

source=301 -> leadsource_id=Gb65Gf345Rfgt3Ed

source=22 -> leadsource_id=bHN54Defr456REF

…and so on.


Is that possible?


Thanks in advance

Michael

Found a solution:


Ex. page with Unbounce form: www.mydomain.com?source=516


<script type="text/javascript"> 

function getParameterByName(name, url) {
if (!url) 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, ' '));
}

var URLsource = getParameterByName('source');

if(URLsource == 516)
{document.getElementById('source_id').setAttribute('value','f7ter36f-ef5c-4b25-84');}
else if(URLsource == 229)
{document.getElementById('source_id').setAttribute('value','80fweb38-dede-43de');}
else if(URLsource == 119)
{document.getElementById('source_id').setAttribute('value','1abd2rtg-51a2-45dd');}
else
{document.getElementById('source_id').setAttribute('value','empty');}
</script>

Reply