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

时间:2019-04-01 08:55:41

标签: wordpress contact-form-7

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

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

位于其他“首选项”标签中,但它不起作用。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

尝试此代码

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/

答案 1 :(得分:0)

product_categories替换为try(Connection conn = dbConfig.getDatabaseConnection()) { PreparedStatement pst = conn.prepareStatement(sql); pst.setInt(1, businessId); List<Product> products = new ArrayList<>(); ResultSet rs = pst.executeQuery(); while(rs.next()) { ... int businessId = rs.getInt("product_categories.businessId"); //<-- This lines throws an exception ... } }

答案 2 :(得分:0)

复制此代码并将其粘贴到子主题的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' );

我尝试了,对我来说很好用