I am not a developer so I am going to share what I know must be done.
I am assuming your idea is that they click a link -> Marketo form appears as a popup -> on submission they are taken to a landing page with the assets or the assets are downloaded on submission.
1 of 1 people found this helpful
I would like the user to click a button to download the asset, then be presented with a gated popup form, which must be filled out to access the asset URL.
Once the form is submitted, then onSubmit it automatically loads the asset URL.
onSuccess, not onSubmit (a crucial distinction that's implicated in all kinds of broken code!).
The demo that Floyd points to is along the lines of what you want, but your need sounds slightly different.
First, you need to add the download URL to your button. If your button is actually a styled <a>, you can use the default href attribute (which you'll override by loading the form instead of going directly to the asset). If it's a real <button> (recommended) then use data-href.
When somebody clicks the button, set a JS variable to the asset URL -- the represents the "last requested download URL" -- and pop up the form.
In the form's onSuccess listener, set
document.location.href = lastRequestedDownloadURL;
and remember to
from the listener to make sure the default Thank You logic doesn't kick in instead.
If I may, I have the impression there is an error in the codepen: in the JS, line 12 should read
lastRequestedDownloadURL = this.getAttribute("data-download-href");
lastDownloadURL = this.getAttribute("data-download-href");
Thanks, yes, I refactored the name to match earlier in the thread and forgot to save!