提交后如何将联系表 7 重定向到另一个页面?

How to redirect contact form 7 to another page after submission?

我试图在单击联系表单提交按钮后重定向到另一个页面,但它不起作用。我正在尝试按照官方指南 https://contactform7.com/redirecting-to-another-url-after-submissions/ 并放置此脚本:

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'http://example.com/';
}, false );
</script>

在附加首选项选项卡中,但它不起作用。我该如何解决这个问题?

试试这个代码

add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '947' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page
location = 'https://www.example.com/thank-you-1/';
} else if ( '1070' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
    location = 'https://www.example.com/thank-you-2/';
} else { // Sends submissions on all unaccounted for forms to the third thank you page
    location = 'https://www.example.com/thank-you-3/';
}
 }, false );
 </script>
 <?php
  }

或者你也可以用这个插件 https://wordpress.org/plugins/wpcf7-redirect/

将您的 location = 'http://example.com/'; 替换为 window.location.href= 'http://example.com/';

复制此代码并将其粘贴到您的子主题的 functions.php 文件中

/**
 * Redirect user to hard coded link when form data is submitted.
 */
function contact_form_login_redirect() {
    ?>
    <script>
        document.addEventListener( 'wpcf7mailsent', function ( event ) {
            location = 'http://example.com/';
        }, false );
    </script>

    <?php
}

add_action( 'wp_footer', 'contact_form_login_redirect' );

我试过了,对我来说效果很好