Form onSuccess refreshes page | Community
Skip to main content
Level 2
October 9, 2024
Solved

Form onSuccess refreshes page

  • October 9, 2024
  • 1 reply
  • 3140 views

Hi, 

I have this code that has a bug in it:

<div class="mktoForm" id="promoForm" mktoName="Promotion Form"></div> <!-- Marketo Form Event Handler Must stay here to load with form--> <script> MktoForms2.whenReady((form) => { form.onSuccess((values, followUpUrl) => { form.getFormElem().hide(); document.getElementById('promoConfirmFormDiv').style.display = 'block'; return false; }); }); </script> <div id="promoConfirmFormDiv" style="display:none;"> <p class="text-white"><strong>${promoFormConfirmation}</strong></p> </div>​
When I submit my form the page still refreshes. When I debug the code the return false is called twice for some reason and on the second call the page refreshes and I tried a few other options, but nothing has worked. Does anyone have any tips to try to assist me? 

Kind regards,
Ethan
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

You have anotheronSuccess function loading from GTM that’s redirecting in a DataLayer event callback (this always overrides an attempt to stay on the page).

 

Common problem as you must coordinate onSuccess functions toward the same final outcome.

1 reply

SanfordWhiteman
Level 10
October 9, 2024

Please use the Syntax Highlighter (“Insert/Edit Code Sample”) when inserting code so it’s readable. I edited your post this time.

 

We need to see your actual page because this code alone is not causing the error.

Level 2
October 9, 2024
SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
October 9, 2024

You have anotheronSuccess function loading from GTM that’s redirecting in a DataLayer event callback (this always overrides an attempt to stay on the page).

 

Common problem as you must coordinate onSuccess functions toward the same final outcome.