Preventing page reload on form submission | Community
Skip to main content
Eve_Yu
New Participant
September 11, 2023
Solved

Preventing page reload on form submission

  • September 11, 2023
  • 1 reply
  • 5791 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

“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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
September 11, 2023

“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
Eve_YuAuthor
New Participant
September 11, 2023

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
Community Manager
September 11, 2023

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?