2 Replies Latest reply on Apr 27, 2017 2:04 PM by Grégoire Michel

    Add script to form

      I need to add a script to forms in:

      1. Forms in marketo landing pages

      2. Forms in non-marketo landing pages


      Whats the best place put to put it?


      1. In the marketo landing page meta tag settings?


      2. Within the embed script?

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

        <form id="mktoForm_1348"></form>

        <script>MktoForms2.loadForm("//app-ab14.marketo.com", "961-UXG-821", 1348);</script>

        • Re: Add script to form
          Grégoire Michel

          Hi Will,


          Aways work within the boundaries of the forms 2.0 API. So, it is for an embedded form, do it inside the script as described in the doc: http://developers.marketo.com/javascript-api/forms/


          The doc also details how to do it on Marketo LP's.



          • Re: Add script to form
            Sanford Whiteman

            Hi Will,


            I wouldn't try to "touch up" the default embed script per se, since anytime someone re-pastes that block from the UI, they'd overwrite anything you might have added to it.


            We most often include a remote form behaviors <script> in the template, bu you can store behaviors anywhere you want, including in an inline <script> tag -- as long as you (a) make sure the forms library is loaded before you reference MktoForms2, and (b) properly document what the script does. Accomplishing (b) can be as simple as giving the script a verbose id (id="formsCustomBehaviors-1.0.1") and/or setting it off with an HTML <!-- comment -->. A script with no labels is what you want to avoid.


            We see a lot of pages with inline <scripts> sprinkled throughout the page, each calling MktoForms2.whenReady or another method. This is really hard to manage over time and getting yourself in the mode of creating a shared, separate behaviors script will pay off later (even if at the beginning it only has a few lines of code).