Form submit redirect not working using Contact Form 7 WordPress plugin
-
21-12-2019 - |
Pergunta
I'm using the Contact Form 7 plugin on my Wordpress site and I found a method to redirect the form to another URL from the documentation on this page.
I tried adding the following code to the additional settings field on my form:
on_sent_ok: "location = 'http://example.com/';"
I tested this on my website at the top of the page via the 'Request a quote' button and submitted. Unfortunately no redirect is forced.
Why is this feature not working? I'm using the form within the lightbox (this could be the reason), but I need to redirect to the homepage when you submit the form as it is a 'one-page' website.
Please feel free to test for yourselves, I only receive the test emails anyway at the moment.
Thanks
Solução
Well, I have a very simple solution:
Just add this to the first of the Messages fields in the Contact form, the one titled: "# Sender's message was sent successfully":
Your message was sent successfully.
<script>window.location.href = 'http://www.example.com';</script>
Outras dicas
<script> window.location.href = 'http://www.example.com';</script>
Try this
on_sent_ok: setTimeout(function(){window.location.href = 'URL_TO';}, 1000);
this one works fine on me... plus the delay time... 1000 = 1 sec
on_sent_ok has been replaced in the latest versions with event-based redirection.
Reference: https://contactform7.com/redirecting-to-another-url-after-submissions/
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
Change http://example.com to the URL you want to redirect to.
Try adding Contact Form 7 - Success Page Redirects plugin. Very simple to use, works very well.
on_sent_ok: "location.replace('/thank-you');"
Still on_sent_ok:
is not working please add below code in your js file.
if ($('.wpcf7-form.sent').length) {
$(location).attr('href', 'http://www.example.com')
}