首页 文章

提交后请联系表格7重定向

提问于
浏览
0

我正在使用联系表单7,我正在尝试在成功提交联系表单后重定向到另一个页面 .

我尝试使用Contact Form 7 - Success Page Redirects(https://nl-be.wordpress.org/plugins/contact-form-7-success-page-redirects/),但该插件与主题不兼容并出现一些错误 .

有没有其他方法可以在不使用该插件的情况下重定向?我也发现了这个https://contactform7.com/redirecting-to-another-url-after-submissions/,但我无法实现它 . 重定向也只是网站上的一个联系表单所必需的,而不是全部 .

谢谢!

J.

3 回答

  • 3

    我已经看到了相同答案的相当多的答案 . 当您有10个表单和10个不同的感谢页面时,主要问题就出现了,这个解决方案将不起作用 .

    我有一个解决方法 .

    第1步:在表单中创建一个隐藏字段,并在其中添加感谢页面URL .

    [hidden thankyouURL id:thankyouURL default:http://example.com/thank-you/ "http://example.com/thank-you/"]
    

    第2步:在DOM事件中,从字段中获取感谢URL并重定向用户 .

    <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        var thankyouURL = document.getElementById("thankyouURL").value;
        location = thankyouURL;
    }, false );
    </script>
    

    而已 .

  • 0

    我正在尝试做同样的事情但却没有成功 . 即将推出on_sent_ok . 查看页面末尾的DOM EVENTS页面,您可以找到特定表单的代码 .

  • 1

    functions.php 中添加以下代码(位于themes - > themeName文件夹中)

    add_action( 'wp_footer', 'mycustom_wp_footer' );
    
    function mycustom_wp_footer() {
    ?>
    <script type="text/javascript">
    document.addEventListener( 'wpcf7mailsent', function( e ) {
        var str = window.location.href;
        if( str.includes("flp") ){
            window.location.href = "http://www.YourWebsite.com/facebook-thank-you";
        } else if( str.includes("glp") ){
            window.location.href = "http://www.YourWebsite.com/google-thank-you";
        }
    }, false );
    </script>
    <?php
    }
    

相关问题