2 of 2 people found this helpful
Sure, you can add custom behaviors to named mktoForm elements on Marketo-hosted pages using the Forms 2.0 API, just as you can with embedded forms on non-Marketo pages.
The key consideration is when you have a named form, Marketo will put the <script> that loads the Forms2 library (forms2.min.js) into the <body> wherever the form is drawn, as opposed to in a predictable location (just before closing </head>, just inside opening <body>, etc.).
And you need to have the Forms2 lib loaded before you start customizing forms behaviors, since the core MktoForms2 object won't exist otherwise.
So you have 2 choices:
- Load your customizations right before the closing </body> tag. This will work, but will be annoying because you might be accustomed to managing external libraries/code in <head>.
- Preemptively load forms2.min.js yourself, right before you load your custom code. This can be done anywhere you want, including in <head>. You will incur the minor overhead of loading the remote script twice (the second one from cache). There won't be any deeper side effects, since Marketo is smart enough to short-circuit the code if MktoForms2 already exists in global scope.
That worked perfectly. Thank you!
Cool, please mark my answer as Correct when you get a chance.