Re: New Tab After Forms 2.0 Submission

Anonymous
Not applicable

New Tab After Forms 2.0 Submission

Hello,

I like to open up the content (a PDF) and another page/tab when a visitor fills out a form on a Marketo landing page.  I've had very good success in generating web activity and additional leads by doing this.

In the past, I've used this code as an HTML element:
<script type="text/javascript">
$jQ('#mktFrmSubmit').click(function() {
var mktErrorMsgContent = $jQ('.mktFormMsg').html();
if (mktErrorMsgContent != 'This field is required') {
window.open('http://url');
}
});
</script>

From this discussion:
https://community.marketo.com/MarketoDiscussionDetail?id=90650000000PYNmAAO

Ths code no longer works with Forms 2.0.  Does anyone have any ideas as to how it can be modified to work with the new forms, if possible?

Thank you,
Alex
Tags (1)
8 REPLIES 8
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

I am also searching for a solution to this. I will report back if I find anything.
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

Is there any update for this?
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

Has anyone found a solution to this yet?
Kenneth_Elking1
Level 3

Re: New Tab After Forms 2.0 Submission

Hey Josh,

Here's the snippet I use:

<script>
MktoForms2.whenReady(function (form){
form.onSubmit(function (){
window.open('', 'myWindow');
});
form.onSuccess(function (values, url){
window.open(url, 'myWindow');
return false;
});
});
</script>
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

Thank you that worked perfectly!
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

Hi Kenneth/Josh,

The code snippet above triggers the popup blocker in Chrome and Firefox, have you found a way to work around that?

--Travis
Kenny_Elkington
Marketo Employee

Re: New Tab After Forms 2.0 Submission

Hey Travis,

It looks like you're right.  I'll check into this.
Anonymous
Not applicable

Re: New Tab After Forms 2.0 Submission

I found a way around the popup blocker issue after submitting a forms 2.0 form and opening the PDF in a new tab.  You need to modify your javascript for the form embed as follows:
=========================================================
MktoForms2.loadForm("//app-sjo.marketo.com", "971-RSF-621", 1249, function (form) {
            //Add an onSuccess handler
            
        });
            MktoForms2.whenReady(function (form){

                form.onSuccess(function (values, url){
                    // Send a "Event" to google analytics to trigger a premium content download for this piece of content
                    _gaq.push(['_trackEvent', 'Premium Content', 'White Paper', 'Name of Article']);

                    // Opens the form's Follow Up URL on successful completion (the asset is specified in the Marketo form config)
                    window.open(url, 'myWindow');
                    form.getFormElem().hide();
                    // add the custom thank you message and download link to the actual asset

                    var thankYou = "";
                    form.getFormElem().before("<p style='padding:10px;width:283px;font-size:14px;color:white;height:100px;text-align:center'>Thank you for downloading.<br/><br/>Your content will open in a new window.</p>");  
                    return false;
                });

                $j("form.mktoForm button.mktoButton").click(function() { 
                    // This is required to get around the popup blocker since the onSuccess event fires asynchronously and the browser thinks it isn't a user-initiated click 
                    window.open('','myWindow');
                    return true;
                });
            });
=========================================
The key is the .click() handler.  You need to open the new window/tab in the onclick event for the submit button.  You can't use the onSubmit handler because that event doesn't fire for some reason if the user is a Known User and you hide the form for known users.  The approach works above in IE, Firefox and Chrome for both the known state (form is hidden) and unknown state (form is visible).