Foms duplicating / not submitting on Marketo landing page | Community
Skip to main content
Best answer by SanfordWhiteman

The situation is much worse than you think.

 

In fact, your forms don’t load at all whenever GTM loads before the forms library (which will randomly happen depending on network conditions).

 

This is because you have some — I must say — atrociously buggy custom JS being injected via GTM:

<script> window.dataLayer = window.dataLayer || []; var origin_open = XMLHttpRequest.prototype.open , origin_send = XMLHttpRequest.prototype.send , form_data = ""; XMLHttpRequest.prototype.send = function(a) { form_data = Object.fromEntries(a); origin_send.apply(this, arguments) } ; XMLHttpRequest.prototype.open = function(a, b) { b.includes("admin-ajax.php") && (this.addEventListener("loadend", function(c) { var d = ["form_id", "form_fields"]; if (JSON.parse(c.currentTarget.response).success) { for (key in form_data) d.some(function(e) { return key.startsWith(e) }) || delete form_data[key], form_data[key] || delete form_data[key]; dataLayer.push({ event: "generate_lead", form_data: form_data }) } }), origin_open.apply(this, arguments)) }; </script>

 

Remove that JS immediately. It has a giant bug in assuming an XHR payload will be an iterable. How would that ever work with a GET?

 

Yes, sometimes you need to override XMLHttpRequest.prototype for instrumentation & analytics, but you simply cannot embark on this without experience.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
May 30, 2025

The situation is much worse than you think.

 

In fact, your forms don’t load at all whenever GTM loads before the forms library (which will randomly happen depending on network conditions).

 

This is because you have some — I must say — atrociously buggy custom JS being injected via GTM:

<script> window.dataLayer = window.dataLayer || []; var origin_open = XMLHttpRequest.prototype.open , origin_send = XMLHttpRequest.prototype.send , form_data = ""; XMLHttpRequest.prototype.send = function(a) { form_data = Object.fromEntries(a); origin_send.apply(this, arguments) } ; XMLHttpRequest.prototype.open = function(a, b) { b.includes("admin-ajax.php") && (this.addEventListener("loadend", function(c) { var d = ["form_id", "form_fields"]; if (JSON.parse(c.currentTarget.response).success) { for (key in form_data) d.some(function(e) { return key.startsWith(e) }) || delete form_data[key], form_data[key] || delete form_data[key]; dataLayer.push({ event: "generate_lead", form_data: form_data }) } }), origin_open.apply(this, arguments)) }; </script>

 

Remove that JS immediately. It has a giant bug in assuming an XHR payload will be an iterable. How would that ever work with a GET?

 

Yes, sometimes you need to override XMLHttpRequest.prototype for instrumentation & analytics, but you simply cannot embark on this without experience.

Level 2
May 30, 2025

Appreciate it. We just inherited this project and don't know what all was going on in there previously. Will take a look at your recommended fix! 

SanfordWhiteman
Level 10
June 2, 2025

I notice the bad code is still there. Are you having trouble finding it in GTM? Because it's kinda bad to have your forms not show up for some people when the fix is that easy!