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.
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).
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.
Sorry, the onSuccess function signature was wrong in the earlier posts and I didn't catch it. I updated it now. Should have been:
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.
Yes, check this past blog post: http://blog.teknkl.com/same-page-thank-you-text-with-marketo-forms-about-the-aliid/
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?
var formEl = form.getFormElem(),
thankYouWindow = window.open('');
thankYouWindow.document.location = followUpUrl;
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.
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?