Mage Creates
  • Home
  • About
    • Testimonials
    • Terms and Conditions
  • Portfolio
  • Services
    • Creative Admin Expert
    • Design & Technology
    • Training & Support
  • Blog
  • Contact Us

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

Home » Plugins, WordPress » Why won’t my Contact Form 7 redirect code work?
Dec, Sun 4th, 2011 Posted in : Plugins, WordPress By : Dani Mage 15 Comments Tags: ajax, contact form 7, contact forms, javascript, plugins, wordpress

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 here:

photo of contact forms 7 redirect 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:

Photo of Contact Form 7 redirect script

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.

 

 

 

 

About Dani Mage

Dani Mage (Founder and CEO) is a writer and the imaginative brains behind Mage Creates. After working in the IT industry for over 8 years in a technical capacity she wanted to venture out on her own and see what kind of trouble she could get into. She was seeking the perfect balance of being practical and creative. Fueled by this desire, she left her cubicle behind and set up Mage Creates with the goal of providing services of both a technical and creative nature for all who needed them. Offering Creative Admin Consulting along with Design & Technology services – Mage Creates solutions for solopreneurs and creative small businesses.

Mail | Web | Twitter | Facebook | More Posts (9)

Share

← HTML Basics: Clean Code
How would you describe your website using just three words? →
  • Webmaster

    I LOVE YOU DANI!!!!
    Like you I tried SEVERAL suggestions, after SEVERAL hours of research.. just as you decridbed!! NONE worked. :-( (

    But what you placed here ABSOLUTELY WORKED!!!!
    Thank you sooooo much for sharing you solution :-) )

    • http://www.magecreates.com Dani M

      My pleasure soooo glad I could help~! I pulled my hair out when I was working on it!

  • Webmaster

    sorry, spelling mistake! I meant “just as you described”

  • Brian Steck

    Dani, that worked as well. (note that if copied, the quotation marks need to be corrected in order to honor unicode character standards – right quote vs. traditional quote marks). I spent days going through all the same forums you mentioned and trying dozens of tests (I think my count was up to 33 trials).

    This fix works, but being type-A, I hate not knowing why. What is keeping the “on_sent_ok” method in the additional settings panel from working?

    If the solution arises, I’d greatly appreciate posting the reply to: http://wordpress.org/support/topic/plugin-contact-form-7-url-redirect-if-wp_footer-not-being-called

  • http://www.fixmytech.com.au/ Uriel

    have you tried manually writing the code below DO NOT COPY PASTE

    on_sent_ok: “location.replace(‘http://www.YOURSITE.com‘);”

    worked for me! :) )))))

  • Jon

    That didn’t work for me, but this did:
    Your message was sent successfully. location.replace(‘http://www.google.com‘);

    • Runkelruebe

      Holy Jesus! Thanks very much! I’ve been literally going nuts trying to make my thank you page redirect work! Contact Form 7 is a great (free) plugin and I appreciate all the work its author has put into it. Nevertheless, I wonder why it doesn’t support this use case out of the box.

      Anyway, thanks again! :-)

  • ikee

    thanks pal!

  • mehul

    i did the above all changes but still its not working

  • jadero

    When I add the location.href=”http://www.yoursite.com/wp-signup.php”; to the messages field, it does not see it as code but text. So, the script appears in the confirmation box of successfully sending a message.

    How did you make it read as code in that message field?

  • http://www.facebook.com/profile.php?id=100003644334252 Brad Taylor

    You saved me some serious coding – now to convince the client why they should move to WordPress!!! Can this be done without it?

    • http://www.danimagestro.com/ Dani M

      Hi Brad,

      Something similar can be done using a statis webiste, Joomla or anything else really. WordPress is awesome though!

  • Pingback: Subby

  • Jodi

    Does this really work? I tried it and nothing’s showing up in my analytics. I’ve read a kazillion posts about this and I’m ready to give up and redirect to a thank you page.

    • Jodi

      Oh, I read it wrong (too many posts I’ve read today) … I was trying NOT to redirect and to use this:
      on_sent_ok: “_gaq.push(['_trackPageview', '/contact-us/thank-you']);”
      in order to track in GA using a virtual page.

      I’ve pretty much given up and redirecting using these instructions works fine for me:
      http://contactform7.com/redirecting-to-another-url-after-submissions/

Email us!

Mage Creates
info@magecreates.com

If you like us and what we do, check out our friends who helped us get here.

Testimonials

It is always hard to switch to a new service provider, even one who comes with such high recommendations as Dani Mage of Mage Creates....

Heidi BK Sloss
www.heidisloss.com

View More Happy Clients

Twitter

No public Twitter messages

(C) 2011 MageCreates
Contact: info (at) magecreates.com