SOLVED

Preventing page reload on form submission

Go to solution
Eve_Yu
Level 2

Preventing page reload on form submission

I've embedded a Marketo form on our website with a 'Stay on Page' thank you page setting, but I've observed that after submitting the form, the page reloads. Is there a way to ensure that I remain on the form's location after submission and the page will not reload? Thanks!

2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Preventing page reload on form submition

“Stay On Page” is indeed somewhat of a misnomer. It would be better called “Reload Same Page” — but it unlikely to be changed after all this time!

 

To remain on the same page and not reload it, return false from a custom onSuccess function.

 

Then do whatever else you want instead of reloading.

MktoForms2.whenReady(function(readyForm){
  readyForm.onSuccess(function(submittedValues,originalThankYouURL){
     /* do whatever else you want to do here, just make sure to return false */
     return false;
  });
});

 

As a very basic example, you can replace the entire form element with static HTML:

MktoForms2.whenReady(function(readyForm){
  const formEl = readyForm.getFormElem()[0];
  readyForm.onSuccess(function(submittedValues,originalThankYouURL){
     /* do whatever else you want to do here, just make sure to return false */
     formEl.innerHTML = "Thank you.";
     return false;
  });
});

 

The Forms 2.0 API is designed to let you add any custom behavior you want instead of reloading/redirecting.

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: Preventing page reload on form submition

GTM itself won't affect redirecting. Custom code injected via GTM absolutely can (but not any more/less than loading that same code in an inline script).

We'll need to see your page.

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Preventing page reload on form submition

“Stay On Page” is indeed somewhat of a misnomer. It would be better called “Reload Same Page” — but it unlikely to be changed after all this time!

 

To remain on the same page and not reload it, return false from a custom onSuccess function.

 

Then do whatever else you want instead of reloading.

MktoForms2.whenReady(function(readyForm){
  readyForm.onSuccess(function(submittedValues,originalThankYouURL){
     /* do whatever else you want to do here, just make sure to return false */
     return false;
  });
});

 

As a very basic example, you can replace the entire form element with static HTML:

MktoForms2.whenReady(function(readyForm){
  const formEl = readyForm.getFormElem()[0];
  readyForm.onSuccess(function(submittedValues,originalThankYouURL){
     /* do whatever else you want to do here, just make sure to return false */
     formEl.innerHTML = "Thank you.";
     return false;
  });
});

 

The Forms 2.0 API is designed to let you add any custom behavior you want instead of reloading/redirecting.

Eve_Yu
Level 2

Re: Preventing page reload on form submition

Thanks for your response. We tried this one, if the web page only embedded the Marketo form, it works. But if the web page has other codes, it doesn't work. Our website developer said that it was caused by Google Tag Manager. Do you have any ideas about it? 

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Preventing page reload on form submition

This shouldn't be happening unless you have conflicting codes/other Marketo forms being loaded via the GTM. Are you able to share the page with GTM and form redirect to the thank you page script deployed?

Eve_Yu
Level 2

Re: Preventing page reload on form submition

Thanks for your response. I think that was the problem with the custom code we implemented in the GTM. I updated the code and it's fine now.  Thanks for your help again. 

SanfordWhiteman
Level 10 - Community Moderator

Re: Preventing page reload on form submition

GTM itself won't affect redirecting. Custom code injected via GTM absolutely can (but not any more/less than loading that same code in an inline script).

We'll need to see your page.
Eve_Yu
Level 2

Re: Preventing page reload on form submition

Thanks for your response. I think that was the problem with the custom code we implemented in the GTM. I updated the code and it's fine now.  Thanks for your help again.