简体   繁体   English

联系表7不重定向发送电子邮件

[英]Contact Form 7 not redirecting upon email sent

I have a form that I am trying to have redirect to http://www.example.com upon successfully sending an email. 我有一个表格,试图在成功发送电子邮件后重定向到http://www.example.com I have tried different approaches including on_sent_ok in the additional settings as well as 我尝试了其他方法,包括在其他设置中使用on_sent_ok以及

if(jQuery('.wpcf7-mail-sent-ok').length > 0)   
window.location.replace("http://stackoverflow.com");

in my JavaScript, but that does not seem to work as well. 在我的JavaScript中,但这似乎不起作用。

Edit: I forgot to mention that upon the user clicking submit, I do a prevent default in order to do some calculations and generate a PDF. 编辑:我忘了提到用户单击提交时,我会进行默认设置以进行一些计算并生成PDF。 Once it is all done I do 一旦完成,我就做

$("form.wpcf7-form").unbind('submit').submit(); 

to allow the submission to happen. 以允许提交。 Could this be causing any issues with the redirection? 这会导致重定向出现任何问题吗?

Contact Form 7 made a ajax call. 联系表7进行了ajax调用。 After success the element is inserted. 成功后,将插入元素。 Then you can check if element exist: 然后,您可以检查元素是否存在:

jQuery(document).ajaxComplete(function() {
  if (jQuery('.wpcf7-mail-sent-ok').length) {
    alert(1);
   //window.location.replace("http://stackoverflow.com");
  }
});

Well, maybe I'm writing late, but this code will definitelly will do the job. 好吧,也许我来晚了,但是这段代码肯定会完成任务。 (If you're working in wordpress). (如果您在Wordpress中工作)。 I'm using it so far and it's working normally. 到目前为止,我一直在使用它,并且它可以正常工作。

Remember to place this code at your functions's file and as final note remember that you must use one or the other, not both...! 请记住将这段代码放在函数的文件中,并作为最后的提示要记住,您必须使用一个或另一个,而不是两者都使用!

add_action('wp_head', 'RedirectsCF7');
// Start of function.
function RedirectsCF7() {

    if(is_page("contact-page-or-whatever-page-name-is")) {

    echo "<script>document.addEventListener('wpcf7mailsent', function(event) {location = 'https://www.google.com/';}, false);</script>";

    }
}

// Or simply add this code to all pages, like this.
    if(!is_admin()) {

    echo "<script>document.addEventListener('wpcf7mailsent', function(event) {location = 'https://www.google.com/';}, false);</script>";

    }
}

Reference here 这里参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM