How to setup URL path to get the value of a hidden field? | Community
Skip to main content
July 1, 2015
Solved

How to setup URL path to get the value of a hidden field?

  • July 1, 2015
  • 2 replies
  • 5462 views

Hi,

I have a form for which I want a hidden field's value to to be automatically populated with a part of the URL of the last page the person visited.

domainname.com/en/products/valueIwanttotrack

I understand the first part of the process which is to hide the field, select a default value, "get value from: Referrer Parameter" but what I don't get is what do I have to put into the parameter name? Tried a couple of options but none are working. I have to track what comes after products/ .

Anyone can help me with this?

I wanted to go into field management and look at some strings to gain a better understanding of the process but all I see is that a field is a "string" but can't see the URL path behind it. How do I get this info?

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

Hmmm...not sure to understand the question? 😕😕

My URLs are built this way:

domainname.com/en/products/productA

domainname.com/en/products/productB

What I want is that when someone come and arrive on my Request for a Quote page that contains a form, I want the form to automatically populate the name of the product that the lead was visiting right before landing on my RFQ page and the name corresponds to the part of the URL coming after products/ in a hidden field.

So if the person is on productA's page, click on Request a quote  and fill the form, the hidden field would show " productA".

Is it more clear? Sorry about the two colors in my answer


Add an HTML block (this example assumes ​product ​is the name of your hidden field, change appropriately);

<SCRIPT>

MktoForms2.whenRead(function(form){

  form.addHiddenFields({ product: document.location.pathname.match(/[^/]*$/)[0] });

});

</SCRIPT>

2 replies

July 2, 2015

Thank you very much, I'll give it a try!

Grant_Booth
New Participant
July 1, 2015

Hi Maude,


When you're setting the field to be hidden and get it's value from a referrer parameter, you can choose the parameter name there. For example, here I set it to "dinner".


Then in the referrer URL, you would use the same parameter name to give a value:

domainname.com/en/products/?dinner=chicken

That would pass through the value "chicken" to the field.

The question mark indicates the beginning of the query string, which follows the root URL and is used to pass parameters and values like this.

Grant

SanfordWhiteman
New Participant
July 1, 2015

But is it a query param, or a REST route (thus part of the path)?

July 1, 2015

Hmmm...not sure to understand the question? 😕😕

My URLs are built this way:

domainname.com/en/products/productA

domainname.com/en/products/productB

What I want is that when someone come and arrive on my Request for a Quote page that contains a form, I want the form to automatically populate the name of the product that the lead was visiting right before landing on my RFQ page and the name corresponds to the part of the URL coming after products/ in a hidden field.

So if the person is on productA's page, click on Request a quote  and fill the form, the hidden field would show " productA".

Is it more clear? Sorry about the two colors in my answer