Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2024-09-10 11:32:02
Original
669 people have browsed it

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

The above is the detailed content of How to fetch full URL and store in hidden field on pardot form. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template