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

Highlighted
Anonymous
Not applicable

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

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.

http://www.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!

8 REPLIES 8
Highlighted
Level 7

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

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".

setparameter.png


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

http://www.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

Highlighted
Level 10 - Community Moderator

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

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

Highlighted
Anonymous
Not applicable

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

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

My URLs are built this way:

http://www.domainname.com/en/products/productA

http://www.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

Highlighted
Level 10 - Community Moderator

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

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>

Highlighted
Anonymous
Not applicable

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

Should I add this somehow in the form itself, in the landing page that contains the form (quote page) or in all the pages that can lead to my landing page (request for a quote page)? I'm a real beginner when it comes to this issue 😕

Thank you very much for your time!

Highlighted
Level 10 - Community Moderator

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

Add it to the Landing Page that contains the form.

The code adds the last part of the URL (i.e. productA or productB) to your form, so it needs to be on the same page as the form.

Highlighted
Anonymous
Not applicable

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

Thank you Grant for your assistance. Something that still isn't clear to me, does it mean I have to change my URLs? If the URL of the pages I want to get the info from are already built but always on the same pattern, is there any possibilities to use them without having to redirect my URLs?

Highlighted
Anonymous
Not applicable

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

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