Can form field visibility be controlled using tokens?

ameliamarie
Level 2

Can form field visibility be controlled using tokens?

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!

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Can form field visibility be controlled using tokens?

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

SanfordWhiteman_0-1744142839125.png

Add it to the form:

SanfordWhiteman_1-1744142849237.png

 

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>

 

 

ameliamarie
Level 2

Re: Can form field visibility be controlled using tokens?

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.

2025-04-08_15-03-48.PNG

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

2025-04-08_15-04-15.PNG

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Can form field visibility be controlled using tokens?

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