代码之家  ›  专栏  ›  技术社区  ›  Steve Walker

将target=“_parent”添加到WordPress联系人表单7的标签?

  •  1
  • Steve Walker  · 技术社区  · 7 年前

    我正在创建一个表单,该表单将被构建到另一个站点中。我想在提交时直接在家长页面上做一个“谢谢”页面。

    谢谢 史蒂夫

    1 回复  |  直到 7 年前
        1
  •  0
  •   Zoli Szabó    7 年前

    如果您使用的是联系人表单7的AJAX版本(默认),那么您可以订阅 wpcf7mailsent 完成时触发的自定义事件,然后设置 top 框架例如:

    <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
        window.top.location = 'http://example.com/thank-you/';
        // Or if the parent window is not the top window, you can use
        // window.parent.location = 'http://example.com/thank-you/';
    }, false );
    </script>
    

    官方文件: https://contactform7.com/redirecting-to-another-url-after-submissions/

    编辑: event 参数对象。例如,仅在特定表单的情况下重定向:

    document.addEventListener( 'wpcf7mailsent', function( event ) {
        if (event.detail.contactFormId == 12) {
            window.top.location = 'http://example.com/thank-you/';
        }
    }, false );
    

    资料来源: https://contactform7.com/dom-events/