Dynamically choosing a form won't record form fill | Community
Skip to main content
Robb_Barrett
Level 10
January 31, 2016
Question

Dynamically choosing a form won't record form fill

  • January 31, 2016
  • 1 reply
  • 1807 views

Hi there -

I wrote some code to dynamically choose the form that is displayed. For example, if you recently filled out a form then on your next visit I present a shorter form that doesn't put name, email, etc on it.

When I run the page it works almost perfectly. The page loads, the form is selected and when clicked it does the appropriate follow up action. When I check the log for the record, the form fill is not recorded and the data values don't change.

Here are the relevant details of the code:

<script type="text/html" id="call-form"></script>

<div class="right-side-container">

                          <div class="right-side-top" id="right-side-top"> </div><!--right-side-top-->

                         <div id="thumbnaildiv" class="thumbnail"></div> <!--thumbnail-->     

                         <div class="this-form" id="this-form"></div><!--this-form-->

                      </div><!--right-side-container-->

<script>

  var knownForm = "{{my.Form ID - Known}}";

  var unknownForm = "{{my.Form ID - Unknown}}";

function pickForm() {

  if ((getFormPassCookie("_mkto_trk") !="") && ("{{lead.First Name}}" != "") && ("{{lead.Email Address}}" != "")) {

    return knownForm;

  } else {

    return unknownForm;

  }

}

var formName = 'mktoForm_'+pickForm();

var formCode = '<form id="'+formName+'"></form>';

document.getElementById("call-form").innerHTML =formCode;

document.getElementById("thumbnaildiv").style.display = "none";

    document.getElementById("right-side-top").innerHTML = document.getElementById("pre-form").innerHTML;

    document.getElementById("this-form").innerHTML = document.getElementById("call-form").innerHTML;

    MktoForms2.loadForm("//app-sj02.marketo.com", "XXX-XXX-XXX", pickForm(),

      function(form) {

      form.vals({"PostalCode":"{{lead.Postal Code}}",

                 "Phone":"{{lead.Phone Number}}",

                 "FirstName":"{{lead.First Name}}",

                 "LastName":"{{lead.Last Name}}",

                 "Company":"{{company.Company Name}}",

                 "Email":"{{lead.Email Address}}",

                 "City":"{{lead.City}}",

                 "Title":"{{lead.Job Title}}",  

                 "web_capture_state":"{{lead.State}}",

                 "Address":"{{lead.Address}}"});

      var formEl = form.getFormElem()[0];

      form.onSuccess(function() {

        setFormPassCookie(val, "true", {{my.Cookie-Days}});

        if (checkForDoc(LinkURL) != true) {

        window.location.assign(LinkURL);

        } else {  

        document.getElementById(formName).style.display="none";

        document.getElementById("right-side-top").innerHTML = postForm;

        document.getElementById("thumbnaildiv").style.display="block";

        document.getElementById("thumbnaildiv").innerHTML = button;

        }

  return false;

      });

    });

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

Robb_Barrett
Level 10
January 31, 2016

Forget this. I found that there's another issue causing problems.

Robb Barrett
February 17, 2016

@Robb Barrett UAT​ Did you end up findng the issue? We are using a form and see its not being logged as a form fill in the activity record of the lead and the form name is coming up empty. Were you seeing that behavior?

Robb_Barrett
Level 10
February 17, 2016

There could be a couple issues.  For one, in the code above I tried using JS to create the form. That didn't work, so i put in tokens for the form ID and it worked better.  That code is a little out of date, but here's the essence of the change.

<script src="//app-sj02.marketo.com/js/forms2/js/forms2.min.js"></script>

<script type="text/html" id="call-form"><form id="mktoForm_{{my.Form ID}}"></form></script>

Next, I realized that if you send an email and click the link and fill out the form with a new email address, it'll create a new record. The email, click and web visit will be credited to the original email address but the form fill will be credited to the new record.

Post your code and I'll see if I can help troubleshoot.

Robb Barrett