简体   繁体   English

联系表 7:不路由到新页面

[英]Contact Form 7 : Not routing to new page

I am using Contact Form 7 and JS to load a new page upon successful form submission.我正在使用 Contact Form 7 和 JS 在成功提交表单后加载一个新页面。 However, upon the submission of the contact form, I am routed to the following url: https://example.com/#wpcf7-f95-p2-o1但是,在提交联系表格后,我被路由到以下网址: https : //example.com/#wpcf7-f95-p2-o1

My inline JS is as follows:我的内联JS如下:

document.addEventListener( 'wpcf7mailsent', function( event ) {
    alert("The form has been sent");
    location = 'http://www.example.com/thank-you/';
}, false );

However, this redirect (to url/#wpcf7-f95-p2-o1) occurs on all browsers and devices, and the alert message never populates.但是,此重定向(到 url/#wpcf7-f95-p2-o1)发生在所有浏览器和设备上,并且永远不会填充警报消息。 There are no console errors or warnings pertaining to this script - which leads me to believe that this script is never being triggered.没有与此脚本有关的控制台错误或警告 - 这使我相信此脚本永远不会被触发。

Is there something that I could have done in order to prevent this function from opperating?为了防止此功能运行,我可以做些什么吗?

Try adding this code to functions.php :尝试将此代码添加到functions.php

add_filter('wpcf7_form_action_url', 'remove_unit_tag');

function remove_unit_tag($url){
    $remove_unit_tag = explode('#',$url);
    $new_url = $remove_unit_tag[0];
    return $new_url;
}

this will remove the tag, also for redirecting, you can use something like this which gives more options这将删除标签,也用于重定向,您可以使用类似这样的东西,它提供更多选项

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

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