Set default values directly on embedded form | Community
Skip to main content
Level 2
July 29, 2021
Solved

Set default values directly on embedded form

  • July 29, 2021
  • 1 reply
  • 2461 views

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.
Best answer by SanfordWhiteman

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); });

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
July 29, 2021

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); });

 

skileyAuthor
Level 2
August 13, 2021