Michael Falciglia
Michael Falciglia

Reputation: 1046

Wordpress Send Form Data on Redirection in Contact Form 7

I'm using the popular wordpress plugin called Contact Form 7. Its easy to redirect the form after submitting to any page by adding this code on_sent_ok: "location = 'http://example.com/';", but it does not carry the form values entered over, because its an AJAX submit.

The sites directions says `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."

Would anyone be able to help or explain how I could carry the form values over on the redirect?

This is the redirection page I got from Contact Form 7

http://contactform7.com/redirecting-to-another-url-after-submissions/

Upvotes: 1

Views: 9342

Answers (4)

Sarah
Sarah

Reputation: 56

To add a 'redirection' function in the Contact Forms 7 you can just use the free plug-in: Redirection for Contact Form 7 by Qube One

Upvotes: 0

Ryon Whyte
Ryon Whyte

Reputation: 106

This is the new way to redirect contact form 7 on submission. Place in functions.php

add_action( 'wp_footer', 'redirect_cf7' );
   function redirect_cf7() {
   ?>
      <script type="text/javascript">
         document.addEventListener( 'wpcf7mailsent', function( event ) {
         location = 'https://www.example.com/thank-you/';}, false );
      </script>
   <?php
}

NOTE: This will redirect all contact form 7 submission to that thank you page

Upvotes: 0

bkj
bkj

Reputation: 1

The on_sent_ok is being phased out.

Note: The method using on_sent_ok hook is no longer recommended. This function is scheduled to be abolished by the end of 2017.

https://contactform7.com/redirecting-to-another-url-after-submissions

Upvotes: 0

Edgar Villegas Alvarado
Edgar Villegas Alvarado

Reputation: 18344

Just use this hook:

on_sent_ok: "location = 'https://gettinmobile.com/my-account/checkout/?level=1&' + $('form.wpcf7-form').serialize();"

This will append all the form data as parameters in the query string.

Cheers, from La Paz, Bolivia

Upvotes: 4

Related Questions