3 Replies Latest reply on Jan 26, 2015 1:24 AM by 043468101e4252afdb21d58f86e0fe4368c613f2

    Set Form 2.0 Target

           Hello,
           I embed the forms on my site through an iFrame to keep the cookie data. With Forms 1.0 I am able to set the target for the Thank you page as parent, so it doesn't open in the iFrame, with this function:
           <script type="text/javascript">
               // set no conflict mode for jquery
             var $jQ = jQuery.noConflict();
            
             $jQ(document).ready(function(){
                 // all form submits will open in a new window
               $jQ('.lpeRegForm').attr('target','_parent');
             });
           </script>
            
           With Forms 2.0, I tried updating the class in that function from '.lpeRegForm' to '.mktoForm' since that is the new class for the form, but it didn't work.
            
           I had a look through the API, but couldn't find any details about setting the target for a form.
            
           Any help would be appreciated.
            
           Thanks
        • Re: Set Form 2.0 Target
          Hey Stephen,

          For your use case, please try the following.

          On a successful form submit, for an iframed forms 2.0 form, this will open the follow-up URL in the parent.  

          MktoForms2.loadForm("//app-sjqe.marketo.com", "718-GIV-198", 621, function(form){
            form.onSuccess(function(values, url){
              window.top.location.href = url;
              returnfalse;
            });
          });

               We're working on another rev of examples for the js documentation (which can be found at: developers.marketo.com) that includes additional canned examples for common use cases like yours.

               Thanks!

               Jason
          • Re: Set Form 2.0 Target
            Hi Jason,
            Thank you for the quick reply!
            I created a marketo landing page that I embed as the iFrame. Will this method work for my use case since the form already gets loaded on the landing page?

            Can I get a form on a marketo landing page, using javascript, and then attach the onSuccess method?
            Thank you
            • Re: Set Form 2.0 Target
              Hi Stephen,

              If you are still looking for a solution, here is a Javascript code you can insert as an HTML elemnent to your iFrame pages:

              <script>
              MktoForms2.whenReady(function (form){
                form.onSuccess(function (values, url){
                  window.open(url, '_parent');
                  /*
                      To open the link on parent page use: '_parent'
                      To open the link in a new tab use: '_blank'
                  */
                  return false;
                });
              });
              </script>

              This will make the form submit action to be exacuted on the parent page.

              Best,