Is there a workaround to have multiple Marketo forms on the same page? | Community
Skip to main content
New Participant
May 11, 2021
Solved

Is there a workaround to have multiple Marketo forms on the same page?

  • May 11, 2021
  • 1 reply
  • 8578 views

Very simple. I need to have the ability to add various Marketo forms on the same page. Is there a way to do this?

Best answer by SanfordWhiteman
There sure is: https://blog.teknkl.com/multiple-forms-multiple-times/

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
May 12, 2021
New Participant
May 13, 2021

Thanks. I'm trying to grasp how that blog post applies to using the Marketo API. Below is the typical code used to render a form on the page and return a response on a successful submission. What I am finding is that when I have two separate forms on the same page(different form ID's) Both form confirmation messages pop and both dataLayer.push() events also fire. How would I change up the code so both forms work on the same page but only fire their own events?

<script src="//app-sj12.marketo.com/js/forms2/js/forms2.min.js"></script> <form id="mktoForm_1234"> </form> <script>MktoForms2.loadForm("//app-sj12.marketo.com", "123-ABC-456", 1234);</script> <!-- Marketo Form Script --> <script> MktoForms2.whenReady(function (form){ form.onSuccess(function(values, followUpUrl){ dataLayer.push({ 'event': 'test event', 'event_category': 'test category', 'event_action': 'test action', 'event_label': 'test label' }); form.getFormElem().hide(); document.getElementById('confirmform').style.display = 'block'; return false; }); }); </script> <!-- Form Confirmation Message --> <div id="confirmform" class="form-confirmation-message"> <div class="form-confirmation-message-header">Thank you for contacting Us.</div> We'll be in contact soon. </div>

 

SanfordWhiteman
New Participant
May 13, 2021

Thanks. I'm trying to grasp how that blog post applies to using the Marketo API

Well, the code in the blog post extensively uses the Forms API, as you can see.

 

But if the snippet you posted is the only code related to forms, there's no reason for both confirmation messages to be displayed — even without the fixes in the blog post.

 

I suspect, though, that isn't the only forms code on your page! Please supply a link to your page so I can inspect.