【发布时间】:2018-05-05 03:48:58
【问题描述】:
我正在创建一个将 iframe 放入另一个站点的表单。我希望在提交时在父页面上重定向到“谢谢”页面。
有没有办法可以将 target="_parent" 属性添加到 Contact Form 7 中的表单标签?
谢谢, 史蒂夫
【问题讨论】:
标签: php wordpress forms iframe contact
我正在创建一个将 iframe 放入另一个站点的表单。我希望在提交时在父页面上重定向到“谢谢”页面。
有没有办法可以将 target="_parent" 属性添加到 Contact Form 7 中的表单标签?
谢谢, 史蒂夫
【问题讨论】:
标签: php wordpress forms iframe contact
如果您使用的是 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 );
【讨论】: