Marketo Embedded Forms 2.0 onSuccess() not firing in rare case

Griffin_Knotts
Level 1

Marketo Embedded Forms 2.0 onSuccess() not firing in rare case

We are running into a rare case where onSuccess() never fires. Here is the setup.

We embed a Marketo form (using Forms 2.0) into a page on our company's website. Our site can be accessed over http and https. Our Marketo domain is go.my.company.com and our website is my.company.com. We've also set up our Marketo domain to work over https.

We load the forms2 script via <script src="//go.my.company.com/js/forms2/js/forms2.min.js"></script>

In certain cases users had a permanent redirect in their local browser cache; they would hit the site over http, the forms2 script would attempt to load over http, then the redirect would apply and it would actually load over https. Whenever this happened the onSuccess() handler would never fire. It seems very strange because the onSubmit() would still fire, and no visible js errors would occur. Once a user cleared their redirect cache the issue went away.

Does anyone know why or how this redirect would cause onSuccess() to not fire?

Below is some slimmed-down sample code for our scenario.

$(document).ready(function () {

var marketoFormHelper = new MarketoFormHelper();

marketoFormHelper.loadForm(1);

}

function MarketoFormHelper() {

this.loadForm = function(marketoFormId) {

MktoForms2.loadForm("[//go.my.company.com]", "[my munckin id]", marketoFormId, function (mktoForm) {

mktoForm.submittable(false);

var $form = $('#' + mktoForm.getFormElem()[0].id);

registerSubmitHandler($form, mktoForm);

mktoForm.onSuccess(function (values, followUpUrl) {

console.log("form submitted successful");

return false;

});

});

}

function registerSubmitHandler($form, mktoForm) {

$form.submit(function (e) {

e.preventDefault();

if (mktoForm.validate()) {

mktoForm.submittable(true);

mktoForm.submit();

}

});

}

}

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo Embedded Forms 2.0 onSuccess() not firing in rare case

This code subverts the Marketo forms event model. Please fix it so it uses the Marketo-specific method for adding event listeners, not adding a DOM submit listener.

In any case what you're probably seeing isn't a standard redirect but an HSTS redirect. If you can come up with a page on which the behavior is reproducible, I can look at it further.

P.S. Please highlight your code as JS, too

Griffin_Knotts
Level 1

Re: Marketo Embedded Forms 2.0 onSuccess() not firing in rare case

Thanks for the response. I might be able to supply an example page later, but currently unable to.

Regarding the DOM submit listener in that sample code, the reason we did it that way was so our custom validation code could run before Marketo's validate(). (I took out the custom validation in the sample.) My understanding is we can run custom validation in the onValidate() callback only after validate() runs.

SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo Embedded Forms 2.0 onSuccess() not firing in rare case

My understanding is we can run custom validation in the onValidate() callback only after validate() runs.

Native validation (if any) runs before custom validation. What situation are you in where you can't simply make the native validation as basic as possible, then run your custom logic?

For example, merely require the field to be non-empty natively, then validate the contents more tightly in the next step. Or don't even bother to require the field natively, do it all in custom JS.