Skip to main content
Jan 12, 2016 6:05 AM UTC
Question

Open New Tab After Form Submission for Downloads

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

51 replies

SanfordWhiteman
User Group Leader
User Group Leader
Jan 12, 2016 7:24 AM UTC
  • In the form's onSubmit listener, open a new window.
  • In the form's onSuccess, set the new window's location to the PDF.
  • Do whatever you want in the original window.

Demo: MktoForms2 :: Thank You New Window

Translate
Jan 12, 2016 8:51 AM UTC

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>

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jan 12, 2016 9:05 AM UTC

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

Translate