【问题标题】:Add target=" _parent" to <form> tag on WordPress Contact form 7?将 target=" _parent" 添加到 WordPress 联系表单 7 上的 <form> 标记?
【发布时间】:2018-05-05 03:48:58
【问题描述】:

我正在创建一个将 iframe 放入另一个站点的表单。我希望在提交时在父页面上重定向到“谢谢”页面。

有没有办法可以将 target="_parent" 属性添加到 Contact Form 7 中的表单标签?

谢谢, 史蒂夫

【问题讨论】:

    标签: php wordpress forms iframe contact


    【解决方案1】:

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

    <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/

    【讨论】:

    • 非常感谢,这已经奏效了。我无法将其添加到 CF7 上的“附加设置”框中,而是将其添加到主题头 PHP 文件的 中。它现在针对网站上的每个表单。有没有办法可以定位特定的表单?
    • 完美!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-31
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 2013-06-19
    相关资源
    最近更新 更多