SOLVED

Using a hidden form field to send url of external page Marketo form is on/filled out from

Go to solution
Brittany_Berli1
Level 2

Using a hidden form field to send url of external page Marketo form is on/filled out from

Marketo's documentation on this isn't very clear for me so I'm hoping someone can help.

 

We have one Marketo form that is embedded on multiple pages on our website.  The internal stakeholders would like form fills to include the url of the page the person filled out the form on, so they can tell which pages are getting more form fills.

The pages do not have querystrings in their url's so I'm not sure parameters will work for this.

 

Is there a way to get the url into a hidden form field?

 

Otherwise I guess my other option would be to create smartlists and use the referrer constraint to split out each page the form is on.

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

1. Add the custom String field LastFormURL to your instance.

 

2. Use this simple JavaScript to pass that hidden field for every form fill:

MktoForms2.whenReady(function (form) {
    form.addHiddenFields({ LastFormURL : document.location.href });
});

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

1. Add the custom String field LastFormURL to your instance.

 

2. Use this simple JavaScript to pass that hidden field for every form fill:

MktoForms2.whenReady(function (form) {
    form.addHiddenFields({ LastFormURL : document.location.href });
});
Brittany_Berli1
Level 2

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

Thanks, Sanford.  Where would I put that script?  On the page on our website the form is on or can I put it in a rich text area on the form?

SanfordWhiteman
Level 10 - Community Moderator

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

You can add it directly after the embed code or if absolutely necessary, you can add it within a Rich Text but only if you do it like this: https://nation.marketo.com/t5/Product-Blogs/HOWTO-Add-Forms-2-0-JS-behaviors-inside-a-Rich-Text-Area...

Brittany_Berli1
Level 2

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

So we tried adding this, but it's not working

 

Brittany_Berli1_0-1612297187159.png

what are we doing wrong?

SanfordWhiteman
Level 10 - Community Moderator

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

Nothing wrong with the code, what's not working exactly?

Brittany_Berli1
Level 2

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

When I do a test form fill and then create a smartlist to see the lastformurl field nothing is populated 

Brittany_Berli1_1-1612298318810.png

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

What's the page this is on?
Brittany_Berli1
Level 2

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

Nevermind, our developers figured it out.  It was in the script as LastFormURL, but the l should have been lowercase.  They changed it to lastFormURL and now it's working. Thank you again!

craluy
Level 1

Re: Using a hidden form field to send url of external page Marketo form is on/filled out from

To expand on this, quick word of advise on this solution. 

Text strings are capped at 255 char. 

the value of document.location.href  will contain URL parameters which could put you over the character limit.

The submission will be rejected if that happens. 

This will help remove the URL parameters  

document.location.href.split('?')[0]

MktoForms2.whenReady(function (form) {
    form.addHiddenFields({ LastFormURL : document.location.href.split('?')[0] });
});