Open New Tab After Form Submission for Downloads

Anonymous
Not applicable

Hi! We are creating a new website and I'm having some trouble with the downloads / resources section. When a visitor fills in a form, they are redirected to the PDF file which is an external URL. This completely closes our website. I do not want this behavior since I want the visitor to stay on our website. What I was thinking is once a visitor submits a form, the PDF opens in a separate tab, but then there's no thank you message after clicking on submit. What's the best way to manage this?

51 REPLIES 51
SanfordWhiteman
Level 10 - Community Moderator

Right now, the PDF opens in a new window onSuccess as expected, when the form is visited anonymously. 

 

I think what else is confusing you is you're using Known Visitor HTML. In that mode, the onSubmit doesn't fire, so you never create the new popup window, as you can see in the browser console.

shilohpaul
Level 2

I see thank you! Is there a way to have it also open in a new tab for a known visitor as well? Right now the download button is not working at all for Known Visitor.

SanfordWhiteman
Level 10 - Community Moderator

I see thank you! Is there a way to have it also open in a new tab for a known visitor as well? Right now the download button is not working at all for Known Visitor.


There is, sorry but I'm too busy to put the code together right now. You might check back in a week.

shilohpaul
Level 2

No worries! Whenever you have time is great - I really appreciate the help! I know it's a weird mix of scenarios.

 

Edit: @SanfordWhiteman any luck? Thank you!

shilohpaul
Level 2

Hi @SanfordWhiteman!

 

We still haven't been able to figure this out. Was hoping you had a chance to look at it. We'd really appreciate any help!

 

Thanks!

rperry04
Level 1

Hi! Facing the same issue with this not working for Known Visitors -- any chance you could share the code to make that happen?

 

Thanks!

SanfordWhiteman
Level 10 - Community Moderator
SanfordWhiteman
Level 10 - Community Moderator

I have this post in Draft mode, look for it this weekend:

 

SanfordWhiteman_0-1619730001900.png

 

Anonymous
Not applicable

Thanks for your reply and pardon my ignorance, but do I just paste those codes after the original script ? What's the purpose of  Email: 'jtestoro@vaneckdemos.com'? Should the link to the PDF be an external link on the form settings?

Here's how my codes look:

<script>// <![CDATA[

MktoForms2.loadForm("//app-e.marketo.com", "846-WED-421", 1469);

// ]]></script>

<script>

MktoForms2.loadForm("//app-sj01.marketo.com", "410-XOR-673", 333);

MktoForms2.whenReady(function(form) {

  var formEl = form.getFormElem()[0],

  thankYouWindow;

  form.onSubmit(function(form) {

  thankYouWindow = window.open('');

  /* force demo values on CodePen */

  form.setValues({

  Email: 'jtestoro@vaneckdemos.com'

  });

  });

  form.onSuccess(function(vals, thankYouURL) {

  thankYouWindow.document.location = thankYouURL;

  formEl.innerHTML = 'Thank you! Your PDF will download in a new window.';

  return false;

  });

});

</script>

SanfordWhiteman
Level 10 - Community Moderator

You definitely do not want the demo email address, and you don't want to load the demo form!  Do not include:

  MktoForms2.loadForm("//app-sj01.marketo.com", "410-XOR-673", 333);

nor

  form.setValues({

  Email: 'jtestoro@vaneckdemos.com'

  });

  });

Should the link to the PDF be an external link on the form settings?

Yes, the PDF is the Thank You/Follow Up URL (isn't that how you already had it?).