Auto-submitting a form for Known Visitors | Community
Skip to main content
SanfordWhiteman
Level 10
Dec 7, 2018 6:22 AM UTC

Auto-submitting a form for Known Visitors

Marketo's Known Visitor HTML (If Known Visitor, Show Custom HTML in Form Editor » Settings) feature is the obvious answer to a few questions:

 

  • “How can I completely ungate an asset — no form fillout at all, just a redirect — if a web session is is already associated with a known person in my instance?”
  • “How can I show just a Download button if a session is already associated?”
  • “How can I auto-submit a form if a session is associated, so I can still switch between the different Advanced Thank You pages in my form setup?”

 

Just redirect

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.)

 

Just a button

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:

 

ss

ss

 

Auto-submit for Known Visitors

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):

 

ss

 

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.

 

The whenReady listener itself runs, and the onSuccess event fires... but neither the onSubmit  event, nor calling submit on the form object, will work.

 

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:

 

ss

 

Copypasta:

{{form.Button:default=Auto-submit}} <script> MktoForms2.whenReady(function(form){ var formEl = form.getFormElem()[0], submitEl = formEl.querySelector(".mktoButton"); submitEl.click(); }); </script>

 

 

 

Notes

[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.

13 replies

SanfordWhiteman
Level 10
Oct 14, 2022 5:19 AM UTC

@anna_blanchet1 of course, your CSS needs to address the slightly different structure, which is like:

<div class="mktoTemplateBox"><div class="klDownload"> <div><span class="klGreeting"><span class="klTokens">Welcome back, Test!*<br></span></span></div> <span class="mktoButtonWrap mktoSimple"><button type="submit" class="mktoButton">Download White Paper</button></span><br><br><br> <div style="text-align: right;"><span class="klGreeting">*<a class="mktoNotYou">Not you? Click here to reset.</a></span></div> </div>
Translate
Disha_Goyal6
Level 6
Oct 14, 2022 4:42 AM UTC

Hi @sanfordwhiteman, thanks for sharing. This is really helpful.

Translate
Anna_Blanchet1
Level 3
Oct 13, 2022 3:54 PM UTC

Thanks @sanfordwhiteman! Is there a way to style the {{form.Button}} token using Custom CSS?  Our form button is styled using Custom CSS but the {{form.Button}} still looks like the default button. 

Translate
SanfordWhiteman
Level 10
Nov 11, 2019 8:13 PM UTC

The Known Visitor HTML -- i.e. the HTML you enter into the Rich Text popup on the Setup tab.

Translate
Kevin_Keefe
Level 2
Nov 11, 2019 7:04 PM UTC

Can I be a real dummy and ask the question...what is the KV HTML?

This is a great post Sanford, thanks as always for your great contributions. 

Translate
Evan_Rittenhous
Level 1
Jul 24, 2019 2:46 PM UTC

@Sanford Whiteman‌ Thanks for this! I have a question - when I try to add <script> or <style> tags to my Known Vistor HTML code (done in the WYSIWYG editor after clicking the HTML tag  ), then apply and save, the tags are removed by something and don't save. Do you know how to fix this so that I can use your code?

Thanks so much for your help!

Translate
SanfordWhiteman
Level 10
Jul 22, 2019 10:37 PM UTC

Is the secondary post you mentioned in the notes available? If so, could you please share the link?

Don't think it made it into a post proper... the bug alluded to above is that Auto-Fill settings are ignored w/KV HTML.

But the fix is already here: MktoForms2 :: KV HTML w/Auto-Fill and Cascade v1.1.0 

Translate
Dilusha_DeTisse
Level 2
Jul 22, 2019 6:29 PM UTC

Yes, the email is sent via Marketo. I didn't realize that the clicked link activity could do that same. For the use case that I described, I think what you mentioned here works. Thanks!!

Translate
Milly_Tsui
Level 2
Jul 22, 2019 6:11 PM UTC

Thanks for posting this, @Sanford Whiteman‌! Is the secondary post you mentioned in the notes available? If so, could you please share the link?

Translate
SanfordWhiteman
Level 10
Jul 21, 2019 2:42 AM UTC

Not sure I understand how the use case requires a hidden form submit, Deanna.

Is the follow-up email sent from Marketo? If so, and if you trust the Clicked Link activity means the person viewed the replay -- optimistic due to mail scanners clicking links, but an automated form submit is also affected by those same scanners -- why do you need a Filled Out Form activity exactly?

Translate