Why won't my Contact Form 7 redirect code work?

Oh Contact Form 7, why don't you love me as much as I love you?

Yeah I'm old school like that. Whew! What a weekend. I was working on a clients WordPress site building a few pages and forms. I generally find this type of stuff super fun. I always learn something new ( ahem, thanks to WordPress being so nuts ) and I get to make my clients happy. Well tonight I ran into an issue with the plug-in Contact Form 7. I normally have no issues using this oldie but goodie classic plug. Yes I know Gravity Form is awesome but it was not an option on this particular clients site. What the client wanted was for the page to redirect once the person clicked the submit button. I researched the heck out of my options and everything pointed to using this code:


on_sent_ok: "location.replace('http://www.mysite.com/mypage.html');"


and entering it into the Additional Settings box at the bottom of the form I created. I found a heap of posts about running away from doing this since Contact Form 7 has a pretty clean "thank you" message. My client wanted me to redirect this page over to her shopping cart because I was using the form for questionnaire and service inquiry setup. She wasn't asking for simply a thank you page. So I skipped over all the opinions and grabbed the code.

I entered the code, clicked Save and checked out the form. I was pretty surprised to see it did not work. I double checked and made sure I was using straight quotes and there were no extra spaces. I had the right URL. So I started reading more about issues with this code and realized, crap, there could be more than a few different reasons why this was not working ( ha, another WordPress lovely ).

A few of the suggestions were to test and see if you had any issues running Ajax, I already knew the site was fine. Of course I went to the Contact Forms 7 website help file and found more advice. It mentioned that if you have tried the above code then you had three reasons why it would not work.

Javascript file is not loaded. It went on to talk about wp_head() and wp_footer() not being in the header.php file. Not true in our case.

It could cause a conflict with other Javascript. This could be possible because plug-ins load their own Javascript. It said that you could run Firebug and sniff out the conflict, which I did and got nothing.

Last it mentioned the HTML structure not being valid and said to use XHTML - CSS Validator to check it. Again not an issue.

So I sat, frustrated as all get out and scratching my little head with one finger. I also found tons of opinions saying to completely remove the plugin, delete files and reinstall. I just had a hunch that would be a waste of time too.

I came across about 25 pages with references to this issue and all of the answers people posted were not working. So I gave it one more go and sure enough. I found the golden ticket.

To my surprise it was actually easier than I thought it would be. Here is the fix I used:

Edit the Messages: "Sender`s message was sent successfully" and add some javascript on the end like so:

Your message was sent successfully. <script> location.href="http://www.yoursite.com/wp-signup.php"; </script>

Yeah, this little buddy right here:


Click photo to view...

That is it ( shakes fist ), yes that is it. So before editing php, javascript and scratching my pointer finger through my skin all the way to my brain...I just needed to google, once again and read more posts. Sometimes half the battle of working with WordPress is never giving up.

Thanks Contact Form 7, my client is happy and the world now has yet another answer to throw in the bucket o' solutions.