Open New Tab After Form Submission for Downloads

Anonymous
Not applicable

Re: Open New Tab After Form Submission for Downloads

I made the changes and that seemed to work, however, that code has added another form to the LP. Check it out: Landing Page 

I tried to clear the form assignment in the new landing page thinking that with the addition of the code, it would have the form appear, but that didn't work. So I added it back in and now there are two forms. Any suggestions to remove the top form which is the one that opens in the same window.

Thank you,

Kevin

SanfordWhiteman
Level 10 - Community Moderator

Re: Open New Tab After Form Submission for Downloads

You don't need to run loadForm() again. When you embed a named form element, loadForm() is inserted for you, so you only need to add the form behaviors (whenReady).

Anonymous
Not applicable

Re: Open New Tab After Form Submission for Downloads

Okay that worked, however, when I clicked Download Now, it opens in a new window/tab but the PDF does not appear (and I have it set for external URL). It opens to our sites homepage. I am trying to get the PDF to open in a new window/tab.

And just to be clear, this is the line of code that I removed: 

MktoForms2.loadForm("//app-ab17.marketo.com", "004-KXL-870", 1058);

Thank you again for your help, Sanford.

Kevin

SanfordWhiteman
Level 10 - Community Moderator

Re: Open New Tab After Form Submission for Downloads

Sorry, the onSuccess function signature was wrong in the earlier posts and I didn't catch it. I updated it now. Should have been:

form.onSuccess(function(vals,followUpUrl) {

Anonymous
Not applicable

Re: Open New Tab After Form Submission for Downloads

Worked like a charm. Thank you so much. You are a lifesaver, Sanford!!

Anonymous
Not applicable

Re: Open New Tab After Form Submission for Downloads

Thanks for this, Sanford! It worked wonderfully. I was wondering is there anything I can add to this code so that when they click submit they get taken to the new window but when they come back to the landing page the form isn't there any longer. Maybe in that box it says something along the lines Thank you for downloading!

Attached is a picture of what the form looks like once I submit and the PDF opens in a new tab.

screenshot.png

SanfordWhiteman
Level 10 - Community Moderator

Re: Open New Tab After Form Submission for Downloads

Jim_McLemore
Level 2

Re: Open New Tab After Form Submission for Downloads

Sanford Whiteman​,

We are trying to add this to a thank you page.  Purpose - We created a thank you page with a bunch of assets. We want to track each asset view as a new form submitted. I created a form with all hidden fields and just a button that redirects to the asset.  We would like the button (form submit) to open up in a new window.

The code we've implemented seems to be opening a new window AND redirecting the existing page, so that it is now open in two windows.  Below is the code we are trying to use.

Any edits we need to make to allow the current page to stay on the same page and the new page to open in a new tab/window?

MktoForms2.whenReady(function(form) {

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

thankYouWindow;

form.onSubmit(function(form) {

thankYouWindow = window.open('');

});

form.onSuccess(function(vals,followUpUrl) {

thankYouWindow.document.location = followUpUrl;

return false;

});

});

SanfordWhiteman
Level 10 - Community Moderator

Re: Open New Tab After Form Submission for Downloads

That JS on its own should work fine. Are you sure you don't have additional form behaviors code (another onSuccess listener) running? This code properly avoids the same-page redirect but another listener could contradict it.

Also, please go back and edit the code in your post and highlight it as JavaScript using the Advanced Editor's Syntax Highlighter:

pastedImage_2.png

Tim_Marcacci
Level 2

Re: Open New Tab After Form Submission for Downloads

Hi Sanford,

I've tested your code from the codepen example you provided, and it works perfectly. Is there a way however to style the text that replaces the form?

Thanks!