Marketo's Known Visitor HTML (If Known Visitor, Show Custom HTML in Form Editor » Settings) feature is the obvious answer to a few questions:
This first one is easy: put a <script> that calls location.redirect in your KV HTML. (You do have to manage the redirect URL in JavaScript; it won't use the Thank You URL(s) as you're skipping the form post entirely.)
The second one is straightforward, too.[1] In the Rich Text editor that pops up when you select Custom HTML, strip everything but the built-in {{form.Button}} token:
The third goal above isn't as easy as you'd expect. If you've dabbled in the Forms 2.0 JS API before, you might think you could do this (purposely screenshot-only so you're not tempted to copy it):
Nope, that won't work!
The reason is a classic bug-you-eventually-round-up-to-intentional: the JS API is not fully supported in KV HTML mode. Important methods like addHiddenFields work, and the whenReady listener itself works, but submit on the Marketo form object doesn't.
So we need to go back to the old-school method of simulating a click event on the button. It works just fine in all browsers, even if primitive:
Copypasta:
{{form.Button:default=Auto-submit}} <script> MktoForms2.whenReady(function(form){ var formEl = form.getFormElem()[0], submitEl = formEl.querySelector(".mktoButton"); submitEl.click(); }); </script>
[1] KV HTML does have an unexpected hidden field autofill (i.e. UTM tracking) gap that relates to the 2nd and 3rd bullets equally, but that's separate enough to be covered in another upcoming post.
Comments