Skip to main content
Level 2
Jun 11, 2022 3:56 PM UTC
Solved

Can I dynamically control a global form field’s visibility based on the page URL the form is hosted on?

I am trying to dynamically control a field’s visibility on a global form using a hidden field that would reference the hosted page URL. Would I be able to use the visibility rules feature. Configuring a hidden field to pull and the URL of the current page?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Jun 11, 2022 6:00 PM UTC

The Visibility Rules part will work fine. But you’ll have to set the Hidden field via JS as there’s no builtin way to fill from the entire current URL. Assuming your field is called Last Marketo Form URL:

MktoForms2.whenReady(function(mktoForm){ mktoForm.setValues({ LastMarketoFormURL : document.location.href }); });

 

3 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Jun 11, 2022 6:00 PM UTC

The Visibility Rules part will work fine. But you’ll have to set the Hidden field via JS as there’s no builtin way to fill from the entire current URL. Assuming your field is called Last Marketo Form URL:

MktoForms2.whenReady(function(mktoForm){ mktoForm.setValues({ LastMarketoFormURL : document.location.href }); });

 

Translate
Level 2
Jun 13, 2022 2:30 PM UTC

@sanfordwhiteman  - Thank you for the reply and proposed solution. Just to be clear this snippet of JS should be on the landing page the form is on,  correct?

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jun 13, 2022 6:24 PM UTC

. Just to be clear this snippet of JS should be on the landing page the form is on,  correct?

Yes, if it’s a Marketo LP, put the code just before the closing <body> tag.

Translate