Skip to main content
Level 2
Jul 29, 2021 6:18 PM UTC
Solved

Set default values directly on embedded form

Hi all. I currently have one global Marketo form that I embed on all our Unbounce landing pages and pass-through values to hidden fields through URL parameters. This has worked great - unless someone sends out the landing page without the correct URL params. Does anyone know if there's a way to set default values directly in my code (and only if there are no URL params passed through)?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Jul 29, 2021 7:04 PM UTC

You’d use the Marketo Forms API’s setValues() method:

MktoForms2.whenReady(function(mktoForm){ const defaultValues = { hiddenField1 : "default value 1", hiddenField2: "default value 2" }; let currentValues = mktoForm.getValues(); let finalValues = Object.keys(defaultValues) .reduce(function(acc,key){ if( !currentValues[key] ) { acc[key] = defaultValues[key]; } return acc; },{}); mktoForm.setValues(finalValues); });

 

2 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Jul 29, 2021 7:04 PM UTC

You’d use the Marketo Forms API’s setValues() method:

MktoForms2.whenReady(function(mktoForm){ const defaultValues = { hiddenField1 : "default value 1", hiddenField2: "default value 2" }; let currentValues = mktoForm.getValues(); let finalValues = Object.keys(defaultValues) .reduce(function(acc,key){ if( !currentValues[key] ) { acc[key] = defaultValues[key]; } return acc; },{}); mktoForm.setValues(finalValues); });

 

Translate
skileyAuthor
Level 2
Aug 13, 2021 8:01 PM UTC

Thanks, @sanfordwhiteman!

Translate