As we know, Contact Form 7 redirects to the same URL as the formโs URL after form submissions in the default settings. However, sometimes, we might need to change this to redirect on another URL after submissions like ‘thank you page’ or need to do some other action on it.
The way is using ‘on_sent_ok’ JavaScript action hook. By using this hook, we can specify a JavaScript code that we wish to run after the form is successfully submitted. We can place it in the Additional Settings field at the bottom of the contact form management page. Simply insert the following line into it:
1 | on_sent_ok: "location = 'http://example.com/';" |
We need to replace the http://example.com/ to the URL you want to redirect to.
So just try it and resolve our problem of redirecting to another url after contact form 7 submission.
Very nice. One question if you can answer it. I would love that i get a message “Thank you for your email” but in the same contact form 7 window. So it collapse/hide and shows that message. Is that possible?
You can set thank you message in Contact Form 7 settings under your dashboard itself using <div id=”response”></div>. Check Contact Form 7 documentation for that.
To collapse/expand you would need some custom JavaScript code to place.
I’m trying to open this new page in a new window. any suggestions?
You can update the code as following to open page in new window:
on_sent_ok: “window.open(‘http://example.com’)”