onSuccess not firing even though form is submitting

kse214
Level 1

onSuccess not firing even though form is submitting

We had a Marketo instance with forms 2.0 submissions working on our website. We created a new Marketo instance. In a staging environment we have added Munchkin tracking to both the new and old instance via: 

 

<script src="//new.mydomain.com/js/forms2/js/forms2.min.js"></script>

 

 

(function() {
  var didInit = false;
  function initMunchkin() {
    if(didInit === false) {
      didInit = true;
      Munchkin.init('NEW-ID', { 'altIds': ['OLD-ID'] });
    }
  }
  var s = document.createElement('script');
  s.type = 'text/javascript';
  s.async = true;
  s.src='//munchkin.marketo.net/munchkin.js';
  s.onreadystatechange = function() {
    if (this.readyState == 'complete' || this.readyState == 'loaded') {
      initMunchkin();
    }
  };
  s.onload = initMunchkin;
  document.getElementsByTagName('head')[0].appendChild(s);
})();

 

 

There are now 2 issues: 

(1) Form submissions on pages that were working with the old instance are not being submitted - the mktoForm.submit() function runs, but onSuccess() never fires and the data IS NOT being captured by Marketo.

(2) New form submissions to the new instance are being submitted and the data IS being captured in Marketo, but also onSuccess() never fires.

 

Here's sample form submission to the new instance, assuming the form ID is 1001 in the new instance:

 

<form id="mktoForm_1001" style="display:none"></form>
form.submit(function (e) {
	e.preventDefault();
	MktoForms2.loadForm("new.mydomain.com",
		"NEW-ID",
		1001,
		function(mktoForm) {
			mktoForm.addHiddenFields({
				"SampleField1": "value"
			});
			mktoForm.onSuccess(function (values, followUpUrl) {
				//redirect here
				return false;
			});
			mktoForm.submit();
		}
	);
});

 

 

And here's a sample submission to the old instance, assuming the form ID is 1005 in the old instance: 

 

<form id="mktoForm_1005" style="display:none"></form>
MktoForms2.loadForm("old.mydomain.com",
	"OLD-ID",
	1005,
	function(mktoForm) {
		mktoForm.addHiddenFields({
			"SampleField1": "value"
		});
		mktoForm.onSuccess(function (values, followUpUrl) {
			//redirect here
			return false;
		});
		mktoForm.submit();
	}
);

 

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: onSuccess not firing even though form is submitting

We created a new Marketo instance. In a staging environment we have added Munchkin tracking to both the new and old instance via: 
<script src="//new.mydomain.com/js/forms2/js/forms2.min.js"></script>

That's not actually Munchkin tracking, it's the Forms 2.0 library (which uses Munchkin if it's present, but doesn't depend on Munchkin).

 

Most likely you're having the known problem where you try to embed forms from 2 different instances; this requires more work than just adding the library twice (it actually will only create a single global object that way).

 

Please provide a URL and I can tell you exactly what's going wrong.