SOLVED

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

Go to solution
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!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
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>

View solution in original post

10 REPLIES 10
Grant_Booth
Level 10

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

SanfordWhiteman
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)?

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

SanfordWhiteman
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>

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!

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

CB_thyssenkrupp
Level 1

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

Hi Sandford,

 

I am looking to do something similar. Would this code work with all URL structures or would it need a change to simply capture the entire URL where a form was filled out?

 

Thank you in advance!

SanfordWhiteman
Level 10 - Community Moderator

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


Would this code work with all URL structures or would it need a change to simply capture the entire URL where a form was filled out?

The code above is specifically designed to get the last path segment. It wouldn’t know if you wanted anything else!

 

If you want the full URL, that’s document.location.href.

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?