SOLVED

Passing program tokens into forms

Go to solution
Highlighted

Passing program tokens into forms

A question for the experts, I'd imagine...

As the global marketing ops lead in a fairly large organisation operating across multiple geos with multiple languages and countries, I'm always trying to make sure that we make our templates as reusable and flexible as possible. This definitely includes forms. I've found a few cool ways to re-use 'custom form fields' with 'form label' tokens, but there are still a few things that I would love to be able to do, which I'm hoping that some clever clogs out there would be able to solve for me!

1) passing a list of values using a program token into a Select field; this would be that for different events, for example, we could use the same standard form, but re-label the custom form field and re-populate the values. No more local forms!

2) setting a Select field default using a program token; we have a number of 'English' forms which are all identical apart from the default value in the Country field. Another example would be setting the value for a 'Product of Interest' field to the relevant product for the campaign concerned...

I know there's a post out there with a bunch of token-specific ideas (I think Gregoire might have posted it...), but if anyone has any thoughts about the two challenges above, I'd really appreciate it.

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level 10 - Community Moderator

Re: Passing program tokens into forms

1) passing a list of values using a program token into a Select field; this would be that for different events, for example, we could use the same standard form, but re-label the custom form field and re-populate the values.

Combine this old-goodie from 2015: MktoForms2 :: Picklist from Variable​ with this JSON embedding technique: https://blog.teknkl.com/safely-embedding-json-in-a-rich-text-as-opposed-to-plain-text-my-token/

2) setting a Select field default using a program token; we have a number of 'English' forms which are all identical apart from the default value in the Country field. Another example would be setting the value for a 'Product of Interest' field to the relevant product for the campaign concerned...

Extremely easy and built-in, call

MktoForms2.whenReady(function(form){

form.setValues({ YourField : "Your Value" });

});

View solution in original post

5 REPLIES 5
Highlighted
Champion Moderator

Re: Passing program tokens into forms

You clearly have to use JavaScript in this case. If I were you, I'd do following:

  • Create a token on the program/folder with comma separated values say {{my.pick_list_values}}
  • Add "rich text" on the form and put this token ( {{my.pick_list_values}} )
  • Hide this rick text using custom CSS on the form
  • Add JavaScript code on the form to extract this token value from the rick text field
  • Add these values in the target select field

This should solve your question #1.

For question two, I would do similar approach.

Tip: You can add this custom JS code on the landing page template. But if you think you have too many templates, you can put the JS code in the same rick text field on the form itself.

Highlighted

Re: Passing program tokens into forms

Thanks, Amit! Between your reply and Sanford's, I've definitely got options!

Highlighted
Level 10 - Community Moderator

Re: Passing program tokens into forms

1) passing a list of values using a program token into a Select field; this would be that for different events, for example, we could use the same standard form, but re-label the custom form field and re-populate the values.

Combine this old-goodie from 2015: MktoForms2 :: Picklist from Variable​ with this JSON embedding technique: https://blog.teknkl.com/safely-embedding-json-in-a-rich-text-as-opposed-to-plain-text-my-token/

2) setting a Select field default using a program token; we have a number of 'English' forms which are all identical apart from the default value in the Country field. Another example would be setting the value for a 'Product of Interest' field to the relevant product for the campaign concerned...

Extremely easy and built-in, call

MktoForms2.whenReady(function(form){

form.setValues({ YourField : "Your Value" });

});

View solution in original post

Highlighted

Re: Passing program tokens into forms

Sanford Whiteman​, you make it sound so simple!

For the second bit, do you have a working example? I'm trying to work out where the best place is to put this function... in the template? If so, what if I DON'T want to set a default?

Highlighted
Level 10 - Community Moderator

Re: Passing program tokens into forms

In the template, sure.

If so, what if I DON'T want to set a default?

MktoForms2.whenReady(function(form){

"{{program.defaultFieldValue}}" && form.setValues({ yourField : "{{program.defaultFieldValue}}" });

});

And just leave the program token empty if you don't want it set at a given level.