"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to fetch full URL and store in hidden field on pardot form

How to fetch full URL and store in hidden field on pardot form

Published on 2024-11-01
Browse:631

This is my code added to the Pardot form below section,

// Parse the URL

function getParameterByName(name) {
name = name.replace(/[[]/, "\[").replace(/[]]/, "\]");
var regex = new RegExp("[\?&]" name "=([^]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/ /g, " "));
}

// Give the URL parameters variable names

var source = getParameterByName('utm_source');
var medium = getParameterByName('utm_medium');
var campaign = getParameterByName('utm_campaign');
var content = getParameterByName('utm_content');
var term = getParameterByName('utm_term');
var campaignID = getParameterByName('URL_Campaign_Id');

// GET the URL of the Parent Page

var url = window.location.href;

// Put the variable names into the hidden fields in the form. selector should be "p.YOURFIELDNAME input"

document.querySelector("p.utm_source input").value = source;
document.querySelector("p.utm_medium input").value = medium;
document.querySelector("p.utm_campaign input").value = campaign;
document.querySelector("p.utm_content input").value = content;
document.querySelector("p.utm_term input").value = term;
document.querySelector("p.URL_Campaign_Id input").value = campaignID;
document.querySelector('input[name="Source_URL"]').value = url;

How to fetch full URL and store in hidden field on pardot form
I want to fetch the URL of the form and store it in the hidden field(Source_URL) when someone submits the Pardot form the whole code works fine but just the part of fetching the URL and storing to "Source_URL" hidden field is not working.

Does anyone have a solution what change do I have to make here?

Adding image of code also to clearly understand the code

Release Statement This article is reproduced at: https://dev.to/darpan_wani_00f6629054089/how-to-fetch-full-url-and-store-in-hidden-field-on-pardot-form-2i0h?1 If there is any infringement, please contact study_golang @163.comdelete
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3