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 = '/';"
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
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./';"
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
Share Improve this question asked Jun 3, 2014 at 13:03 TimTim 2,64910 gold badges35 silver badges39 bronze badges7 Answers
Reset to default 2<script> window.location.href = 'http://www.example.';</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./redirecting-to-another-url-after-submissions/
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example./';
}, false );
</script>
Change http://example. 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.')
}
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.';</script>