wordpress 使用 on_sent_ok 重定向联系表 7 不起作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17921032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Contact Form 7 redirect with on_sent_ok doesn't work?
提问by Danijel
I tried using the on_sent_ok
to redirect after form submit for Contact Form 7 (Wordpress plugin), but it doesn't work for some reason:
我尝试on_sent_ok
在表单提交后使用to redirect for Contact Form 7(Wordpress 插件),但由于某种原因它不起作用:
on_sent_ok: "location.replace('http://www.company.com/thank-you/');"
Why wouldn't this work?
为什么这行不通?
I am using CF7 versions 2.2.1 and Wordpress 3.5.0.
我使用的是 CF7 版本 2.2.1 和 Wordpress 3.5.0。
回答by Sanjeev Thakur
Contact Form 7 Thank You Page Redirects THE OLD METHOD: on_sent_ok hook is no longer recommended. I have a code you can copy and paste. You can add that method bottom of your functions.php file, add this code:
联系表格 7 谢谢页面重定向旧方法:不再推荐 on_sent_ok 钩子。我有一个代码,您可以复制和粘贴。您可以在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>
回答by SilverNightaFall
Try this...
尝试这个...
on_sent_ok: "location = 'http://example.com/';"
in additional settings
在其他设置中
回答by REZzzz
Had the same problem with my own Wordpress theme. After an hour I understood that forgot to add <?php wp_footer(); ?>
in footer.php, so important Contact 7 scripts doesn't load. When I add it everthing worked.
我自己的 Wordpress 主题也有同样的问题。一个小时后我明白忘记添加<?php wp_footer(); ?>
footer.php,所以重要的Contact 7 脚本没有加载。当我添加它时,一切都奏效了。
回答by buzztone
on_sent_ok not working in Contact Form 7 normally indicates a Javascript conflict with either your current WordPress theme or one of the other plugins you are using - see Contact Form 7 Email Issues- there is a link there that covers Javascript Conflicts.
on_sent_ok 在联系表 7 中不起作用通常表示 Javascript 与您当前的 WordPress 主题或您正在使用的其他插件之一发生冲突 - 请参阅联系表 7 电子邮件问题- 那里有一个涵盖Javascript 冲突的链接。
Remember that a problem in one script can cause issues in another.For example, some jQuery errors can stop jQuery processing any more script, which can make the culprit hard to find.
请记住,一个脚本中的问题可能会导致另一个脚本出现问题。例如,一些 jQuery 错误可能会停止 jQuery 处理任何更多脚本,这会使罪魁祸首难以找到。
A jQuery error in one of your plugins or your themes javascript files can stop jQuery processing before it gets to the CF7 script.
一个插件或主题 javascript 文件中的 jQuery 错误可能会在 jQuery 处理到达 CF7 脚本之前停止它。
Use Firebugor Chrome Dev Toolsto examine Javascript conflicts in detail.
使用Firebug或Chrome Dev Tools详细检查 Javascript 冲突。
See http://wiki.simple-press.com/installation/troubleshooting/plugin-conflicts/for general guidance.
有关一般指导,请参阅http://wiki.simple-press.com/installation/troubleshooting/plugin-conflicts/。
回答by Ian Schneider
I've tried both solutions: on_sent_ok didn't work and adding redirect javascript didn't do the job either.
Eventually, I found myself editing the file 'submissions.php' inside the 'modules' folder of 'contact-form-7'.
look for: private function submit()
in there, look for elseif ( $this->mail()
I've commented $this->response = $contact_form->message( 'mail_sent_ok' );
and just put header("Location: www.somesite.com/");
Works pretty well.
我已经尝试了两种解决方案: on_sent_ok 不起作用,添加重定向 javascript 也不起作用。最终,我发现自己正在编辑“contact-form-7”的“modules”文件夹中的“submissions.php”文件。寻找:private function submit()
在那里,寻找elseif ( $this->mail()
我评论过的,$this->response = $contact_form->message( 'mail_sent_ok' );
并且将header("Location: www.somesite.com/");
Works放置得很好。
回答by Ashar Zafar
Contact form 7 Redirecting to Another URL After Submissions
联系表格 7 提交后重定向到另一个 URL
First you need to update contact form 7 on new version i try it on v7.4.9 and then place a contact form short code in any page and place this JS script any where on page and change url where need to redirect your page after submission
首先,您需要在新版本上更新联系表单 7,我在 v7.4.9 上尝试,然后在任何页面中放置一个联系表单短代码,并将此 JS 脚本放置在页面上的任何位置,并更改提交后需要重定向页面的 url
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
For more info click contact form 7 official site https://contactform7.com/redirecting-to-another-url-after-submissions/
欲了解更多信息,请点击联系表格 7 官方网站 https://contactform7.com/redirecting-to-another-url-after-submissions/
回答by Raja Rama Mohan Thavalam
I faced same problem in contact form 7 latest version 4.8.1 .
我在联系表格 7 最新版本 4.8.1 中遇到了同样的问题。
finally solved issue using custom jquery code.
最终使用自定义 jquery 代码解决了问题。
if ($('.wpcf7-form.sent').length) {
$(location).attr('href', 'http://www.example.com')
}
Note: Contact form 7 form successful submit adding class "sent" to form field .
注意:联系表单 7 表单成功提交添加类“发送”到表单字段。