Open New Tab After Form Submission for Downloads | Community
Skip to main content
January 12, 2016
Question

Open New Tab After Form Submission for Downloads

  • January 12, 2016
  • 1 reply
  • 15528 views

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.

1 reply

SanfordWhiteman
New Participant
January 12, 2016
  • 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

January 12, 2016

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
New Participant
January 12, 2016

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