我希望看到我能否在我正在进行的项目上得到一些帮助。
我现在已经迷失了,但我需要做的是当用户填写表单时,如果他们选择了一个下拉菜单并选择了主页单选按钮以及他们输入圣地亚哥邮政编码它会将它们带到该下拉列表中的任何URL。
如果他们没有输入圣地亚哥邮政编码,则会根据下拉列表将他们带到国家页面。那部分实际上是完全完整和有效的。客户端转过身来说,如果他们选择办公室单选按钮和列表中选定的下拉菜单之一,则会将他们带到办公室版本页面,无论该下拉列表是什么。无论是送水,咖啡服务还是水过滤。
我完全迷失了如何根据不同的单选按钮进行网址重定向,因此他们需要家庭单选按钮才能进入常规下拉菜单和办公室时选择完全不同网址基于办公室选项。因此,这将是办公室供水或办公室咖啡服务。
我非常不确定如何根据一个办公室单选按钮选择进行三种不同的网址重定向。无论如何,我真的可以用手来谢谢你了。源代码如下。感谢
<script type="text/javascript">
function setAction(nPage){
document.forms[0].action = nPage;
}
</script>
<div class="home-form">
<form method='get' id='gform_1' action='http://50.22.79.62/~pftech/form-handler/'>
<div class="serviceinput"
<label for="services">Services: </label>
<select id="selection" name="selection">
<option value=''>Select a Service</option>
<option value='http://50.22.79.62/~pftech/water-delivery-service/'>Water Delivery</option>
<option value='http://50.22.79.62/~pftech/coffee-delivery/'>Coffee Services</option>
<option value='http://50.22.79.62/~pftech/water-filtration-systems/'>Water Filtration</option>
</select>
</div>
<div class="zipcode">
<label for="zip">Zip Code: </label>
<input name="zip" type="text" maxlength="5" id="zip" /></div>
<div class="frontradio"><input name="home" type="radio" id="homeradio" />
<div class="homelabel"> <label for="homeradio">Home</label></div>
<input name="home" type="radio" id="officeradio" />
<label for="officeradio">Office</label></div>
<div class="homebutton">
<input type='submit' id="submithome" name="did_submit" value="Get Started!">
</div>
</div>
</form>
</div>
FORM HANDLER:
<?php
if(isset($_GET['zip'])){
$sandiego = array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173', '92562', '92563', '92590', '92591', '92592', '92596');
if (in_array($_GET['zip'], $sandiego)){
header("Location: ".$_GET['selection']."?zip=".$_GET['zip']."&type=".$_GET['type']);
} else {
header("Location: http://www.pureflo.com/");
}
}
exit;
?>
表格实际上是:
http://50.22.79.62/~pftech/
答案 0 :(得分:2)
我认为你正在混淆你的优先事项。例如,不要将目标ID放入这些选项值。使用普通值,如“1”,“2”,“3”等。
“魔法”发生在您的评估方法中。 首先,评估是否选择了家庭或办公室。
if($_GET["home"] == 1) { //Assumes that selecting 'office' returns you this value.
} else {
}
接下来,在该选择内,使用目标数据填充数组。
$urls = array();
if($_GET["home"] == 1) { //Assumes that selecting 'office' returns you this value.
$urls[] = "http://50.22.79.62/~pftech/water-delivery-service/"
//rinse and repeat
} else {
$urls[] = "http://45.22.79.62/~pftech/water-delivery-service/"
//rinse and repeat
}
此时,您有一个有效的数组,它与选定的下拉框相关,直接与所选的单选按钮相关。
$URL = $urls[$_GET["selection"]];
现在您只需要将该URL传递给标题函数,就可以了。
仅为了完整起见,这是建议的代码:
处理程序:
<?php
if(isset($_GET['zip'])){
$sandiego = array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173', '92562', '92563', '92590', '92591', '92592', '92596');
if (in_array($_GET['zip'], $sandiego)){
$urls = array();
if($_GET["home"] == 1) { //Assumes that selecting 'office' returns you this value.
$urls[] = "http://50.22.79.62/~pftech/office_water-delivery-service/"
$urls[] = "http://50.22.79.62/~pftech/office_coffee-delivery/"
$urls[] = "http://50.22.79.62/~pftech/office_water-filtration-systems/"
} else {
$urls[] = "http://50.22.79.62/~pftech/home_water-delivery-service/"
$urls[] = "http://50.22.79.62/~pftech/home_coffee-delivery/"
$urls[] = "http://50.22.79.62/~pftech/home_water-filtration-systems/"
}
if($_GET['selection'] < 3 && $_GET['selection'] >= 0) {
$URL = $urls[$_GET['selection']];
header("Location: $URL?zip=$_GET[zip]");
} else header("Location: http://www.pureflo.com/"); //Illegal input
} else {
header("Location: http://www.pureflo.com/");
}
}
exit;
?>
您选择框的HTML将如下所示:
<select id="selection" name="selection">
<option value='-1'>Select a Service</option>
<option value="0">Water Delivery</option>
<option value="1">Coffee Services</option>
<option value="2">Water Filtration</option>
</select>
我希望这会有所帮助。