首页 文章

Wordpress联系表单7根据下拉列表中的条目将用户重定向到特定页面

提问于
浏览
0

我正在尝试制作一个联系表单,根据他在下拉菜单中的输入将用户发送到一个新的“隐藏”页面 .

我的联系表格如下:

I'm interested in:
[select subject id:subject "Construction" "Professional Services" "Financial Services" "Wholesale" "IT & Telecom" "Industry" "Transport & Logistics"]

Leave your e-mail address to unlock more information about your preferred subject:
[email* your-email]

[submit "Send"]

我希望表单的用途是当用户选择“构建”,输入他的电子邮件地址并提交表单时,他将被引导至“www.example.com/construction/”,其他选项也是如此在下拉列表中,都有自己的网址 .

提前致谢!

2 回答

  • 0

    下面的代码逻辑应该让你接近 . 你可能不得不把它拆开一点并重构,但这无论如何都会帮助你更好地理解它 . 这是现场demo . G'luck!

    <form onSubmit="return checkAnswer();">
      <input id="answer" type="text" maxlength="55" class="box" autofocus />
      <input type="submit" class="submit" value="SUBMIT" />
      </form>
      <script>
      function checkAnswer(){
          var response = document.getElementById('answer').value;
          if (response == "correctanswer")
              location = 'http://www.correcturl.com';
          else
              location = 'http://www.wrongurl.com';
          return false;
      }
      </script>
    
  • 0

    成功提交后,您可以将不同的值重定向到不同的URL .

    Example:

    <script>
    jQuery(document).ready(function($){
        $(".wpcf7").on( 'mailsent.wpcf7', function(){
            var redirect_to = $(this).find('#subject').val();  // Enter your drop-down id
            if( typeof(redirect_to)!=='undefined' && redirect_to!='' ){
                window.location.href= redirect_to;
            }
        });
    });
    </script>
    

相关问题