lizyjeywin lizyjeywin - 7 days ago 5
jQuery Question

prefill Marketo fields on Submit

On submit of Marketo form it does some processing and returns back to the same page.

My requirement

I would like to have all the Marketo fields populated with the just entered data (data entered before clicking Submit button)for all the Marketo fields.

What I have tried

I have used the below code, that's given in http://developers.marketo.com/blog/external-page-prefill/

<script>
MktoForms2.whenReady( function(form) {
//set the first result as local variable
var mktoLeadFields = mktoLead.result[0];
//map your results from REST call to the corresponding field name on the form
var prefillFields = {
"Email" : mktoLeadFields.email,
"FirstName" : mktoLeadFields.firstName,
"LastName" : mktoLeadFields.lastName,
"Company" : mktoLeadFields.company
};
//pass our prefillFields objects into the form.vals method to fill our fields
form.vals(prefillFields);
}
);
</script>


But when the form submits and loads\returns back its not populated with previos entered data

Answer

I checked the declared variable - here its

var mktoLeadFields

(given in Q) and made a logic that assigned the pre-enetered value to that var and then when set the form values with

form.vals(prefillFields);

it worked.