简体   繁体   English

根据下拉选择联系表单7重定向

[英]Contact Form 7 Redirect Based on Drop-Down Selection

Been searching for an answer for this across the web. 一直在网上寻找答案。 Everything I find doesn't seem to help. 我发现的一切似乎都没有帮助。 I know this is totally wrong too - I don't know enough about JS to get it to work. 我知道这也是完全错误的 - 我不太了解JS让它发挥作用。 Any help would be appreciated. 任何帮助,将不胜感激。

4 options in a dropdown in Contact Form7 (on wp site). Contact Form7下拉列表中的4个选项(在wp站点上)。 Depending on which option chosen, redirect to the appropriate paypal payment page. 根据所选的选项,重定向到相应的paypal付款页面。

Here is JS added to page in WP. 这是在WP中添加到页面的JS。

function paypalRedirect() {

        if (document.getElementsByName("eventPackage")[0].selected) {
            location.href = 'http://www.test1.com';}
        if (document.getElementsByName("eventPackage")[1].selected) {
            location.href = 'http://www.test2.com';}
        if (document.getElementsByName("eventPackage")[2].selected) {
            location.href = 'http://www.test3.com';}
        if (document.getElementsByName("eventPackage")[3].selected) {
            location.href = 'http://www.test4.com';}   
    };

And here is the additional setting in Contact Form 7: 以下是联系表7中的附加设置:

on_sent_ok: "paypalRedirect();"

Everything works fine witht the form, I just can't get the redirect to work. 一切都很好用的形式,我只是无法让重定向工作。 And I don't see any errors in the console...Thanks 我在控制台中没有看到任何错误......谢谢

Keep in mind that Contact Form 7 will abolish the on_sent_ok hook: 请记住,联系表格7将取消on_sent_ok挂钩:

Note: The method using on_sent_ok hook is no longer recommended. 注意:不再推荐使用on_sent_ok钩子的方法。 This function is scheduled to be abolished by the end of 2017. ( https://contactform7.com/redirecting-to-another-url-after-submissions/ ) Thats why we need a different approach with DOM events ( https://contactform7.com/dom-events/ ) 此功能计划在2017年底之前废除。( https://contactform7.com/redirecting-to-another-url-after-submissions/ )这就是为什么我们需要一个不同的DOM事件方法( https:// contactform7.com/dom-events/

Contact Form 7 gives an example for the redirect: 联系表7给出了重定向的示例:

document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = 'https://www.example.com';
}, false );

I would also be interested in how we can combine the dom redirect with a dropdown option 我也对如何将dom重定向与下拉选项结合起来感兴趣

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

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