SOLVED

Re: Marketo form - opening new tab on submission for external URL

Go to solution
AndrewELMO
Level 1

Marketo form - opening new tab on submission for external URL

Regarding the code below - is there a way to make this work only for a specific form ID?

 

I tried using if (formId == xxxx) in there but couldn't get it working.

Any help would be appreciated.

 

 

MktoForms2.whenReady(function(form) {
var formEl = form.getFormElem()[0],
thankYouWindow;
form.onSubmit(function(form) {
thankYouWindow = window.open('');
});
form.onSuccess(function(vals, thankYouURL) {
thankYouWindow.document.location = 'https://info.tmforum.org/rs/021-WLD-815/images/dtw-2019-event-brochure.pdf';
formEl.innerHTML = 'Thank you! Your asset has opened or downloaded in a new window.';
return false;
});
});

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form - opening new tab on submission for external URL

MktoForms2.whenReady(function(form) {
  const formEl = form.getFormElem()[0],
      formId = form.getId();

  const newTabFormIds = [1234,5678];
  
  if( newTabFormIds.includes(formId) ) {
    let thankYouWindow;

    form.onSubmit(function(form) {
      thankYouWindow = window.open('');
    });
    form.onSuccess(function(vals, thankYouURL) {
      thankYouWindow.document.location = 'https://info.tmforum.org/rs/021-WLD-815/images/dtw-2019-event-brochure.pdf';
      formEl.innerHTML = 'Thank you! Your asset has opened or downloaded in a new window.';
      return false;
    });
  }
});

View solution in original post

2 REPLIES 2
SanfordWhiteman
Level 10 - Community Moderator

Re: Marketo form - opening new tab on submission for external URL

MktoForms2.whenReady(function(form) {
  const formEl = form.getFormElem()[0],
      formId = form.getId();

  const newTabFormIds = [1234,5678];
  
  if( newTabFormIds.includes(formId) ) {
    let thankYouWindow;

    form.onSubmit(function(form) {
      thankYouWindow = window.open('');
    });
    form.onSuccess(function(vals, thankYouURL) {
      thankYouWindow.document.location = 'https://info.tmforum.org/rs/021-WLD-815/images/dtw-2019-event-brochure.pdf';
      formEl.innerHTML = 'Thank you! Your asset has opened or downloaded in a new window.';
      return false;
    });
  }
});
AndrewELMO
Level 1

Re: Marketo form - opening new tab on submission for external URL

Thank you, Sandford!

 

Much appreciated.