Allow tokens to pre-populate hidden form fields in Forms 2.0

Allow tokens to pre-populate hidden form fields in Forms 2.0

Rather than create additional smart campaigns/flows to accomodate this, it would be really useful if system tokens (or even a local token) can be used as the default value for a form field - often times these are hidden fields.  For example, when someone opts-in to receive future email communications from us, we need to date-stamp an "optin date" field with the time/date that this took place.  To be able to use the {{system.dateTime}} token as the default value would be very convenient.
14 Comments
Jeff_Smith3
Level 7
This would be nice. I am wanting to use a hidden field in our forms to determine product interest. The problem is that I don't want the new product interest to replace the old one; I want it appended to what is already there. The default value would look something like this:

{{lead.Product Interest}}; Interest X

This could potentially create a string of 2 or more product interests on a lead. I can add this in the Fills Out Form flow steps, but it would be nice to have it contained within the form.
Grégoire_Miche2
Level 10

That would make usage of global forms much more efficient. Issues such as setting a lead value based on the program values would be made very easy, even if it can also be set with change data values in a "fills our form" trigger campaign.

-Greg

SanfordWhiteman
Level 10 - Community Moderator

This is already possible by including tokens in the page that hosts the form.

mktoPreFillFields['my_field__c'] = "{{my.program_token}}";

Grégoire_Miche2
Level 10

Hi Sanford Whiteman,

Do you mean simply in the HTML? or in a webready forms 2.0 callback? in a script?

And this would work only on a Marketo LP or also on any web page where the form is embedded?

Where is this documented? I have not been able to find this on developers.marketo.com.

Thanks,

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Do you mean simply in the HTML? or in a webready forms 2.0 callback? in a script?

In the above example, it's an HTML block containing a one-line <SCRIPT> tag.  As long as it loads above the form it will be included when the form loads. 

Otherwise you can have a true Forms 2.0 API whenReady callback, also included as an HTML block, and form.addHiddenFields({field:"{{token}}"}).  Same idea.

And this would work only on a Marketo LP or also on any web page where the form is embedded?

On a Marketo LP.  Embedded forms continue to have the usual restriction about data leakage.

Where is this documented? I have not been able to find this on developers.marketo.com.

It's not documented.

Grégoire_Miche2
Level 10

Hi again Sanford,

Thx a lot, that's really useful.

-Greg

Anonymous
Not applicable

I also want to say Thanks for documenting this, Sanford. This was the path I was about to go down, as it's been a couple years since I setup a form and really thought this would be integrated into the Forms Builder by now, since so many people have asked for it. (You can set default values off Referrer Info, URL Parms, but not a Marketo Token?!?)

Anyhow, I will just put in a javascript block that utilizes the Forms2 JS Library to set this one field off the token value and the token will swap out prior to the form loading.


Again, thanks for confirming before I did the coding.

SanfordWhiteman
Level 10 - Community Moderator

Sure thing.

Dan_Stevens_
Level 10 - Champion Alumni

Sandy, how to precisely place code like this within guided LPs - in this case, above the form?  So, not at the template level, but in an actual LP.

Grégoire_Miche2
Level 10

Hi all,

FYI, this in fact works. I created the following LP to test and demo it:

Token in hidden field demo

The setup is:

form:
pastedImage_3.png

field:

pastedImage_4.png

If you want that the token value always get to the hidden field, just make sure that the form prefill on the hidden field is disabled. If you only want the token to enter the field if it's empty, leave prefill enabled.

-Greg