Can form field visibility be controlled using tokens? | Community
Skip to main content
Level 2
April 8, 2025
Question

Can form field visibility be controlled using tokens?

  • April 8, 2025
  • 1 reply
  • 705 views

Hello!

 

I'm using a global form for events, and while most fields stay consistent, certain events occasionally require unique fields (e.g. Title, Company Name, Dietary Restrictions). 

 

Is there a way to conditionally show or hide specific fields based on a token value? For example, can I hide a field unless a program token like {{my.TokenName}} is present or has a specific value? I'd love to manage field visibility dynamically without having to clone or create separate forms for each event. 

 

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
Level 10
April 8, 2025

Sure. Create a field (we usually have a few of these) specifically for visibility management:

Add it to the form:

 

That’s the field you use in Visibility Rules.

 

Set the field value using using HTML & JS like this:

<datalist class="mktoFields"> <option label="my.Some Token">{{my.Some Token}}</option> </datalist> <script> document.addEventListener("DOMContentLoaded", function(e){ MktoForms2.whenReady(function(readyForm){ readyForm.setValues({ formVisibilityManagerA: document.querySelector(`datalist.mktoFields [label="my.Some Token" i]`)?.value; }); }); }); </script>

 

 

AmeliaDaAuthor
Level 2
April 8, 2025

Thank you, @sanfordwhiteman I appreciate your help with this.

I am missing a step or applying something incorrectly somewhere, can you help me identify where I'm going wrong?

 

As a test, I have created a token called {{my.Add Company Title Fields}} with the value as true.

Not sure if the value is relevant or not. 

 

I have modified the form, adding visibility rules on the Company Name and Job Title fields.

I have tried Is and Contains with the token name (is this supposed to be the value of the token, not the name of it?)

I have applied the JS on the landing pages, ensuring that the token and Form Visibility Manager names are correct.

SanfordWhiteman
Level 10
April 9, 2025

The Visibility Rules use the different values of the {{my.token}}.