AnsweredAssumed Answered

Is it possible for two MktoForm2 methods to run on a single page?

Question asked by Raj Ruprai on Jul 27, 2018
Latest reply on Jul 27, 2018 by Raj Ruprai

Hi,

 

As an example, we have two MktoForm2 methods that are added to a page (see example below): form.onSubmit() and form.onSuccess(). We used this Documentation. In this example, we conditionally want to do something once the form is submitted, but not necessarily when it was submitted successfully since it is not critical to the form submission, but does need to be added to the page.

 

// This is added via GTM when an event is triggered such as "page url = /some/path/"
<script type="text/javascript">
  MktoForms2.whenReady(function(form) {
    form.onSubmit(function() {
      // do something.
      document.write("<div>hello</div>");
    });
  });
</script>

 

 

// This is added from our CMS when the page loads.
<script type="text/javascript">
  MktoForms2.loadForm("//app-abb.marketo.com", "082-KNA-087", 3469, function(form) {
    // On successful submission, push the dataLayer event to GTM.
    form.onSuccess(function(values, url) {
      // do something.
      location.href = url;
      return false;
     });
  });
</script>

Outcomes