AnsweredAssumed Answered

Auto populate form from Marketo cookie and auto submitting the form

Question asked by 5e3081a5c89a3a912bcd5ff7ac7e5831f7c2d1c4 on Mar 2, 2017
Latest reply on Mar 2, 2017 by Sanford Whiteman


we want a way to track a lead who clicks on a PDF link from a mail that is not sent out via Marketo. We also do not wish to Gate the PDF file (Require our clients to fill in a form) to access the file. After talking to support and scouring the Marketo fourms and support sites, I understood (I think) the only way to achieve this is to make a REST API call and try and get the lead information from the cookie file on their PC (People who will access our PDF's are known clients and not the general public) I am no expert coder, so I patched up this code from my research, suffice to say it is not working and any help will be appreciated.


<script src="//"></script>

<form id="mktoForm_2244" style="display:none"></form>

<script>MktoForms2.loadForm("//", "xxx-xxx-xxx", 2244);</script>



MktoForms2.whenReady(function(form) {


  //OnSuccess is optional - only if you need to make client-side decisions about Thank You URL

  form.onSuccess(function(vals, tyURL) {

    location.href = ''; 

    return false;



     //Get LEAD info from cookie

     var mktoGet = new XMLHttpRequest();"GET", "<cookie>&fields=email,firstName,lastName&access_token=<token>", false);



    //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" :,

            "FirstName" : mktoLeadFields.firstName,

            "LastName" : mktoLeadFields.lastName



    //pass our prefillFields objects into the form.vals method to fill our fields



  //Submit the form





p.s. I replaced the <cookie> and <token> values and once I paste the link in the browser I get a sucess result.