Can I dynamically control a global form field’s visibility based on the page URL the form is hosted on? | Community
Skip to main content
New Participant
June 11, 2022
Solved

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

  • June 11, 2022
  • 1 reply
  • 2209 views

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.
Best answer by SanfordWhiteman

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 }); });

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
June 11, 2022

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 }); });

 

New Participant
June 13, 2022

@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?

SanfordWhiteman
New Participant
June 13, 2022

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