Javascript Wordpress联系人表单7根据下拉列表中的条目将用户重定向到特定页面
我正在尝试创建一个联系人表单,根据下拉列表中的条目将用户发送到一个新的“隐藏”页面 我的联系方式如下所示:Javascript Wordpress联系人表单7根据下拉列表中的条目将用户重定向到特定页面,javascript,jquery,wordpress,forms,contact-form-7,Javascript,Jquery,Wordpress,Forms,Contact Form 7,我正在尝试创建一个联系人表单,根据下拉列表中的条目将用户发送到一个新的“隐藏”页面 我的联系方式如下所示: I'm interested in: [select subject id:subject "Construction" "Professional Services" "Financial Services" "Wholesale" "IT & Telecom" "Industry" "Transport & Logistics"] Leave your e-mail
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
提前谢谢 成功提交后,您可以将不同的值重定向到不同的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>
jQuery(文档).ready(函数($){
$(.wpcf7”)。在('mailssent.wpcf7',函数()上{
var redirect_to=$(this).find('#subject').val();//输入您的下拉id
if(typeof(redirect_to)!='undefined'&redirect_to!=''){
window.location.href=重定向到;
}
});
});
下面的代码逻辑应该可以让您接近。您可能需要将其拆分一点并进行重构,但这将帮助您更好地理解它。这是现场直播。祝你好运
函数checkAnswer(){
var response=document.getElementById('answer')。值;
如果(响应=“正确答案”)
地点:http://www.correcturl.com';
其他的
地点:http://www.wrongurl.com';
返回false;
}
谢谢你的回答。你能解释一下我需要把这个代码放在哪里,我需要把下拉列表的id和不同的url放在代码的哪里吗?@JSBdesign我已经更新了我的答案。请将此代码放入footer.php
?谢谢。但我还是不明白。在代码中,我需要把下拉id放在哪里(在你指出的那一行中),我需要把url放在代码中的任何地方吗?设置一个答案数组,生成哪些url,然后重定向到submitThanks,我不太擅长javascript,你能告诉我我可以使用什么代码吗?
<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>