SOLVED

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

Go to solution
Goldengaines
Level 1

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

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

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

 

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

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

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

 

Goldengaines
Level 1

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

@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
Level 10 - Community Moderator

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


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