SOLVED

Re: Auto Submit Marketo Form on Page Load

Go to solution
Phillip_Wild
Level 10 - Community Advisor

Re: Auto Submit Marketo Form on Page Load

Hi Sanford

Here's the link: http://letsgo.gadventures.com/Agent---National-Geographic-Content-Loading.html

The page it is linking to is built off a new template, yes.

Thanks, Phil

SanfordWhiteman
Level 10 - Community Moderator

Re: Auto Submit Marketo Form on Page Load

The problem is you are creating a crazy race condition in the order you're firing events. It only seems to work at all (and only in some browsers) when an error due to a timing combo allows the redirect to process. It's basically an infinite loop.

The order should be

1. MktoForms2.loadForm()

2. MktoForms2.whenReady() (not​ inside loadForm())

     a. form.onSuccess()

     b. form.submit()

Hence

MktoForms2.loadForm('//app-ab06.marketo.com', '110-AIL-152', 1417);

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 = 'http://letsgo.gadventures.com/Agent---National-Geographic-Journey-Content-Requested.html';

    return false;

  });

  form.submit();

});

Phillip_Wild
Level 10 - Community Advisor

Re: Auto Submit Marketo Form on Page Load

Thanks Sanford! That works perfectly to submit the form. However, I've run into another problem.

When the form submits, it seems to be submitting under an anonymous lead. Here's my process:

1. I send an email to myself using my work email.

2. I click a button which has specific URL parameters which populate my hidden form.

3. The form submits in the background and automatically redirects to the landing page.

In my activity log, I can see the email delivery and the email click activities. But, I don't see any "filled out form" activities - in fact, I see them appear in an anonymous lead (which I found by using a "filled out form" smart list). So somehow I'm losing the association, and it's being assigned to an anonymous lead.

To try to mitigate this, I put "email address" as a hidden field and populated it via the URL as well. This simply meant that my anonymous lead now gained an email address - instead of Marketo deduping it as mine! Bizarre.

I've checked the page template and the only scripts that are there are these two:

<script src="//templates.marketo.net/template2/js/script.js"></script> (default Marketo script in the template)

and

<script>

MktoForms2.loadForm('//app-ab06.marketo.com', '110-AIL-152', 1417); 

MktoForms2.whenReady(function(form) { 

form.submit(); 

}); 

</script>

Any ideas?

Thanks again. Phil

SanfordWhiteman
Level 10 - Community Moderator

Re: Auto Submit Marketo Form on Page Load

Can you send me the (non-sample) email?

You also must QA test using Incognito windows, or you will get confounding results w/r/t cookie assoication.

Phillip_Wild
Level 10 - Community Advisor

Re: Auto Submit Marketo Form on Page Load

Sure! PM me your email address.

Thanks in advance.

Phil

Phillip_Wild
Level 10 - Community Advisor

Re: Auto Submit Marketo Form on Page Load

Sanford Whiteman​ has solved it! Basically, I was loading the form twice on the page - once through the Marketo editor in a guided landing page, and once more in the Javascript in the template itself. Which was making multiple form submissions! Once I removed the redundant loadForm line, it worked like a charm.

Chris_Vanderma1
Level 4

Re: Auto Submit Marketo Form on Page Load

Great Thread, and thanks for showing examples Phil and Sanford! I've just successfully implemented this to solve a problem. Much appreciated!