I'm having a bizarre issue when attempting to use a JS snippet to display an onSubmit "thank you" message, instead of redirecting the form to another page.
I've placed the below script in a hidden rich text field in the form template. The script works, however, the "Success Message" is showing multiple times. Adding this script to the landing page template works as intended, however this won't work in our scenario, because we do want some forms to redirect to other pages, instead of displaying a thank you message.
Here's a link to an example page: https://go.arria.com/td_form_success_test.html
if (typeof MktoForms2 !== 'undefined') {
MktoForms2.whenReady(function (form) {
const $form = form.getFormElem()
form.onSuccess(values => {
const { FirstName } = values
const $successMessage = $(`
<div class="successMessage">
<p>Thank you ${FirstName}!</p>
<p>We will be in touch shortly to talk to you about our product.<p>
</div>
`);
$form.after($successMessage)
$form.hide()
return false
})
})
}
Not bizarre! See: