[英]Wordpress contact form 7 redirect user to specific page based on entry in dropdown
I'm trying to make a contact form that sends the user to a new 'hidden' page based on his entry in the drop down. 我正在尝试创建一个联系表,根据用户在下拉菜单中的输入将其发送到新的“隐藏”页面。
My contact form looks like this: 我的联系表格如下所示:
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"]
What I want the form to do is when a user selects 'Construction', enters his e-mail address and submits the form, he will be directed to 'www.example.com/construction/', and the same for the other options in the drop down, all with their own url. 我要表单要做的是,当用户选择“构建”时,输入其电子邮件地址并提交表单,他将被定向到“ www.example.com/construction/”,其他选项也一样在下拉菜单中,都带有自己的网址。
Thanks in advance! 提前致谢!
You can have different value redirecting to different URLs after successful submission. 成功提交后,您可以将不同的值重定向到不同的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>
This code logic below should get you close. 下面的代码逻辑将使您接近。 You may have to take it apart a little and refactor, but that'll help you understand it better anyways. 您可能需要将其拆开一点并进行重构,但是无论如何这将帮助您更好地理解它。 Here is the live 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.