【问题标题】:Contact Form 7 Redirect to different URL on form submit depending upon dropdown select联系表格 7 根据下拉选择重定向到表单提交时的不同 URL
【发布时间】:2021-08-24 03:03:19
【问题描述】:

我正在将此代码用于联系表 7 中的下拉菜单:

[select* menu-student id:menustudent include_blank "Student" "Professional"]

我想如果一个选择Student,然后在提交表单后,它会重定向到学生页面,如果选择Professional,它会在提交表单后进入专业页面。

我已经使用了这里提到的这段代码。

这是我添加的代码:

<script>
inputs = event.detail.inputs;
inputs.forEach( function(el) {
    if ( el.name == 'menu-student' ) {
        if ( el.value == 'Student' ) {
            location.href = 'https://google.com';
        } else if ( el.value == 'Professional' ) {
            location.href = 'https://facebook.com';
        }
    }
});
</script>

但它不会为我重定向。

谁能指出我哪里做错了?

我也使用了以下脚本,但没有任何结果:

document.addEventListener( 'wpcf7submit', function( event ) {
  var lpLocation =  document.getElementById("menustudent").value;
  if (lpLocation == "Student") {
    location = 'https://facebook.com/';
  } else if (lpLocation == "Professional") {
    location = 'https://google.com/';
  }
}, false ) 

任何帮助表示赞赏。

【问题讨论】:

    标签: contact-form-7


    【解决方案1】:

    我对上面的代码做了一些修改,它对我有用。

    这里是任何人需要的代码:

    <script>
    document.addEventListener( 'wpcf7mailsent', function( event ) {
      var lpLocation =  document.getElementById("menustudent").value;
      if (lpLocation == "Student") {
        location = 'https://google.com';
      } else if (lpLocation == "Professional") {
        location = 'https://facebook.com';
      }
    }, false );
    </script>
    

    您需要根据自己的需要更改 ID 和选择。

    谢谢。

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 1970-01-01
      • 2017-12-03
      • 2017-09-28
      • 1970-01-01
      • 2019-10-11
      • 1970-01-01
      • 2015-05-05
      • 2021-05-07
      相关资源
      最近更新 更多