Wordpress Send Form Data on Redirection in Contact

2019-02-20 21:10发布

问题:

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/

回答1:

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



回答2:

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



回答3:

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