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)?
Solved! Go to Solution.
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);
});
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);
});