Redirecting to Another URL After Submissions

First of all, I believe that this tip I’m writing on this post is not necessary for 99.99% of users and, actually, I don’t recommend using it. I’m writing this for the 0.01% of you, so you can ignore it if not necessary.

As you know, Contact Form 7 redirects to the same URL as the form’s URL after form submissions in the default settings. However, in very rare cases, you might need to change this to make it redirect to another URL after submissions. I’ll write in this post how you can set up Contact Form 7 to do just that.

By the way, I’m often asked by users that how they can redirect to so-called “Thank You Page”. In most cases, they want to know it because they assume that redirecting to “Thank You Page” is necessary for tracking form submissions with Google Analytics. That’s not necessary at all. In fact, it’s an outdated and nonsense custom. Today you can track submissions with Google Analytics without any redirection.

So you have other reason for redirecting to another URL? Okay. I’ll show you the procedure.

The simplest way is using on_sent_ok JavaScript action hook. By using this hook, you can specify a JavaScript code that you wish to run after the form is successfully submitted. You will find the Additional Settings field at the bottom of the contact form management page. Simply insert the following line into it:

on_sent_ok: "location = '';"

Obviously, you need to replace the to the URL you want to redirect to.

on_sent_ok example

That’s it. So simple, isn’t it? Try it and check if it works.

If it doesn’t work, check if Ajax is correctly working on your site. It is a JavaScript hook, so it needs JavaScript to work. You’ll need another hack if you need to redirect on non-JavaScript environments.

Just another contact form plugin for WordPress. Simple but flexible.