Re: Prevent Marketo Form loading too many times?

Anonymous
Not applicable

Prevent Marketo Form loading too many times?

Hi everyone, not too great with javascript, and looking for help from anyone who is willing to.

I have a Marketo form code that works great on all my pages. It is responsive and displays a message after submit. I was assigned to create a form also to be loaded from a modal/lightbox. But every single time I close the lightbox and load it again, the form is being displayed twice.

So my question is, how would I in a way clear my form after closing lightbox? Or reset all values after on load? Does this make sense? I want the form to load only once every time it is being called. Thanks for your help.

Code:

<body>

<script src="//app-sj08.marketo.com/js/forms2/js/forms2.min.js"></script>

<script>MktoForms2.loadForm("//app-sj08.marketo.com", "861-RWS-699", 1261, function(form) {});</script>

  

          <div class="boxPadding" style="background-color:#FFF; margin:0px 40px 0px 40px;">

      

        <!--  1 COLUMN-->

      

                     

            <form id="mktoForm_1261"></form>

            <ul class="mktoUL">

                            <li>

                            <p id="confirmform" style="visibility:hidden;"><span class="paddingArticlePage"><span class="paragraphArticlePage"><b>Thank you. You are now subscribed to Nanette Abuhoff Jacobson Commentary.</b></span></span></p>

                            </li>

                        </ul>

          <!--  END 1 COLUMN-->

        

    </div>

  

 

    <!-- on submit hide form and show hidden div -->

  

<script>

MktoForms2.whenReady(function (form){

//Add an onSuccess handler

  form.onSuccess(function(values, followUpUrl){

   //get the form's jQuery element and hide it

   form.getFormElem().hide();

document.getElementById('confirmform').style.visibility = 'visible';

   return false;

});

});

</script>

</body>

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Prevent Marketo Form loading too many times?

That code has no reference to the Marketo .lightbox() feature. Please post the actual code (link to a runnable URL is even better) and I'll show you how it's done.  It sounds like you may be reloading the entire form from scratch when someone clicks a button, but you're also preventing it from being destroyed the first time, so you get a duplicate form. But there's no lightbox in the code you posted here.