Lightbox Forms: Can we append custom HTML and why no prefill? | Community
Skip to main content
Robb_Barrett
Level 10
August 17, 2016
Question

Lightbox Forms: Can we append custom HTML and why no prefill?

  • August 17, 2016
  • 4 replies
  • 4074 views

Wondering if anyone <cough>@Sanford Whiteman​ </cough> has an example of appending custom HTML to a lightbox.  I'd like to put program-specific information on the top of the lightbox, such as "Fill out this form to learn more about ABC..."

Also, why no prefill on Lightbox forms embedded on a Marketo LP?

This is kind of a dealbreaker for using the Lightbox function.  It might be better to replicate with CSS.

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

4 replies

gkrajeski
Level 10
August 17, 2016

Yes, we are doing this at PR Newswire.

To prefill the lightbox we're using Forms 2.0 and custom JS to do the fill.

See here: Engage in Social Conversations around a Brand​ as the first example, then go here: Media Monitoring Solutions Buyer’s Guide | PR Newswire

gkrajeski
Level 10
August 17, 2016

Although, this is on our website, and not LPs, but definitely a solid alternative.

SanfordWhiteman
Level 10
August 18, 2016

How are you managing DoS attacks against your API call limit tho...

SanfordWhiteman
Level 10
August 17, 2016

Prefill works automatically on lightboxed forms, but you have to use a true Form (mktoForm) Element + MktoForms2.whenReady(). If you use the embed code it'll be treated as foreign JS with no special treatment.

If you must use the embed code on an LP for some reason, you can still use prefill. Create the window.mktoPreFillFields object w/tokens. I posted an example some time back.

Robb_Barrett
Level 10
August 17, 2016

OK, here's the code I'm using which is the same code I use on other pages, with the addition of the lightbox line. Are you saying that I want to replace the form.vals (or encapsulate it within) a whenReady()? Or is the problem that I'm showing the lightbox too early?

function showMainForm() {

  document.getElementById("form-div").innerHTML = document.getElementById("form-html").innerHTML;

    MktoForms2.loadForm("//app-sj02.marketo.com", "005-SHS-767", {{my.Form ID}},

      function(form) {

      MktoForms2.lightbox(form).show();

      form.vals({"web_capture_country":"{{lead.Web Capture Country}}",

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

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

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

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

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

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

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

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

                 "PostalCode":"{{lead.Postal Code}}",

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

                 "form_product_interest":getFPI(),

                 "formProgramID": getCampID(),

                 "flexField1": getDPI(),

          "facility_type":"{{lead.Facility Type}}"

                });

     

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

     

  MktoForms2.whenReady(function(form){

     document.getElementById("mktoForm_{{my.Form ID}}").setAttribute("autocomplete","on");

     document.getElementById("Email").setAttribute("autocomplete","email");

      document.getElementById("Phone").setAttribute("autocomplete","tel");

      document.getElementById("FirstName").setAttribute("autocomplete","given-name");

      document.getElementById("LastName").setAttribute("autocomplete","family-name");

      document.getElementById("Company").setAttribute("autocomplete","organization");

      document.getElementById("City").setAttribute("autocomplete","address-level2");

      document.getElementById("web_capture_state").setAttribute("autocomplete","address-level1");

      document.getElementById("Title").setAttribute("autocomplete","organization-title");

      document.getElementById("PostalCode").setAttribute("autocomplete","postal-code");

      document.getElementById("Address").setAttribute("autocomplete","street-address");

        });     

     

      form.onSuccess(function() {

          window.location.assign(LinkURL);

    return false;

      });

    });

  }

Robb Barrett
SanfordWhiteman
Level 10
August 18, 2016

There's no reason manually setting the field values from tokens (which you were already doing, now that I remember) won't work with a lightbox. Check here: MktoForms2 :: nation.marketo.com/thread/3473​.

While someone reading the code might think it makes more sense to set the values before loading the lightbox, it makes no real difference. Also no problem injecting HTML, as I also show in the demo link. I suspect something else is going on on this page (maybe a JS syntax error). If you post the real URL I can tell ya.

Robb_Barrett
Level 10
August 18, 2016

GE Healthcare | Centricity Clinical Archive | Demo

Click the "Contact Us" and/or wait 15 seconds into the video.  If you fill out a form, use @example.com

Robb Barrett
Robb_Barrett
Level 10
August 18, 2016

BTW - prefill seems to be working now.

I suspect that my Dear Company rolled out some new "helpful" security software last night which hosed my ability to connect to Marketo.  I'm on VPN now and it seems to be working a bit better.  Hopefully I just need some software updates to fix the issue.

Robb Barrett