我尝试使用 on_sent_ok
在 Contact Form 7(Wordpress 插件)的表单提交后重定向,但由于某些原因它不起作用:
on_sent_ok: "location.replace('http://www.company.com/thank-you/');"
为什么这行不通?
我使用的是 CF7 版本 2.2.1 和 Wordpress 3.5.0。
最佳答案
Contact Form 7 感谢页面重定向 旧方法:不再推荐 on_sent_ok Hook 。我有一个代码,你可以复制粘贴。您可以将该方法添加到您的 functions.php 文件底部,添加以下代码:
<pre>
<code>
add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '97' == event.detail.contactFormId ) {
location = 'http://www.vizistata.com/affordable-logo-designs.php';
}
else if ( '634' == event.detail.contactFormId ) { // 634 is the form id
location = 'http://www.vizistata.com/#blog';
}
else if ( '635' == event.detail.contactFormId ) { // 635 is the form id
location = 'http://www.vizistata.com/#contact';
}
else if ( '636' == event.detail.contactFormId ) {
location = 'http://www.vizistata.com/#services';
}
else if ( '94' == event.detail.contactFormId ) {
location = 'http://www.vizistata.com/#about';
}
else { // Sends submissions on all unaccounted for forms to the third thank you page
location = 'http://www.vizistata.com/';
}
}, false );
</script>
<?php
}</pre>
</code>
关于javascript - 使用 on_sent_ok 的 Contact Form 7 重定向不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17921032/