Recent searches
No recent searches
Redirect after successfully submitting form
Posted Feb 01, 2023
Hi there,
I've created a custom 'successful submission' page that should appear after a user has filled out and submitted a form. Now I need to create a redirect from a successfully completed form to that custom page.
The following code has been recommended to me, and it works whenever the user submits the form. The problem is that it works EVERY time, including when there are errors (e.g., required fields are blank) and the form is not actually submitted. That is, the user can 'submit' a blank form which is not actually sent, and they would still be redirected to the 'successful submission' page.
Can someone please recommend a way to redirect to the custom page only after the form is actually submitted?
<script>
if (document.referrer.match('/requests/new') && (window.location.href.indexOf("/requests/new?ticket_form_id=") === -1)) {
window.location.href = 'URL';
}
</script>
Thanks!
0
2 comments
Amy Giella
Hi Ahmed Zaid,
Thank you for taking a look at this! I used this in the document.head.hbs after replacing "URL" with the custom page's URL. It does make the user fill in all the required fields before submitting the form, but instead of taking me to the custom page, I am taken back to the main home page. Am I maybe adding the code to the wrong place? I'm not sure what else to try.
0
Brittany Loy
Great, this works for me however it bypasses the required fields. What else can I do to ensure when submitting it won't bypass the required fields so the user must fill out the required fields first and then submit the form, which still redirects?
0