0

我希望看看我是否可以从我正在从事的项目中得到一些帮助。

我现在非常迷茫,但是我需要做的是,当用户填写表单时,如果他们选择了其中一个下拉菜单并选择了主页单选按钮,并且他们输入了圣地亚哥的邮政编码,则需要他们到该下拉列表中的任何 URL。

如果他们不输入圣地亚哥邮政编码,则会根据下拉菜单将他们带到国家页面。这部分实际上已经完全完成并且可以正常工作。客户然后转身说,如果他们选择了办公室单选按钮和列表中选定的下拉菜单之一,它会将他们带到办公室版本页面,无论该下拉菜单是什么。无论是送水、咖啡服务还是水过滤。

我完全不知道如何根据不同的单选按钮进行 url 重定向,因此他们需要 home 单选按钮转到常规下拉菜单,并且在选择办公室时需要转到基于完全不同的 url办公室选项。因此,它将是办公室供水或办公室咖啡服务。

我非常不确定如何根据一个办公室单选按钮选择进行三种不同的 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>
        &nbsp;
        <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>

表单处理程序:

<?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/
4

1 回答 1

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>

我希望这有帮助。

于 2013-04-17T20:42:29.450 回答