2017-05-30 42 views
0

我正在嘗試製作一個聯繫表單,用於根據用戶在下拉菜單中的條目將用戶發送到新的「隱藏」頁面。Wordpress聯繫表單7根據下拉菜單中的條目將用戶重定向到特定頁面

我的聯繫形式如下:

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/',對於下拉列表中的其他選項也是如此,全部使用自己的url。

在此先感謝!

+0

設置導致哪些URL,然後重定向提交 –

+0

感謝答案的數組,我沒那麼親的JavaScript,你能告訴我,我可以使用什麼樣的代碼是什麼? – JSBdesign

回答

0

成功提交後,您可以將不同的值重定向到不同的URL。

例子:

<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> 
+0

感謝您的回答。你能解釋一下我需要放置這些代碼的位置,以及代碼中我需要放置下拉列表的id和不同的url的位置嗎? – JSBdesign

+0

@JSBdesign我已經更新了我的答案。你能把這段代碼放在你的'footer.php'中嗎? – purvik7373

+0

謝謝。但我仍然不明白。在代碼中,我需要將下拉ID(在您指定的那一行中的哪個位置),並且我必須將該URL放在此代碼中的任何位置? – JSBdesign

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> 
相關問題