0

我想要工作的是,当用户填写表格时,如果他们在下拉菜单中选择一项服务以及主页单选按钮并输入正确的圣地亚哥邮政编码,则将他们带到该页面中落下。如果他们没有输入正确的圣地亚哥邮政编码,它会自动将他们重定向到全国页面。我遇到的问题是单选按钮。我需要做的是,当用户从列表中选择一个下拉菜单并选择 office 单选按钮时,它将他们重定向到 office 版本,无论该下拉菜单是什么。他们还必须在此处输入正确的 SD zip,否则将被发送到全国页面。我真的需要帮助才能正确重定向,我以为我用当前的代码就可以了,但我只是被重定向到主页下拉选择,即使选择了办公室单选按钮。有人可以请帮我解决这个问题,我现在非常迷茫,想不出为什么它不起作用。谢谢

形式:

<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='-1'>Select a Service</option>
                <option value="0">Water Delivery</option>
                <option value="1">Coffee Services</option>
                <option value="2">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>
    </form>
</div>

表单处理程序:

<?php
/**
 * Template Name: 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)){
          $urls = array();
            if($_GET["home"] == 1) { 
                $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
                $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
                $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
            } else {
                $urls[] = "http://50.22.79.62/~pftech/water-delivery-service/";
                $urls[] = "http://50.22.79.62/~pftech/coffee-delivery/";
                $urls[] = "http://50.22.79.62/~pftech/water-filtration-systems/";
            }
            if($_GET['selection'] < 3 && $_GET['selection'] >= 0) {
                $URL = $urls[$_GET['selection']];
                header("Location: $URL?zip=$_GET[zip]");
            } else header("Location: http://50.22.79.62/~pftech/nationwide/"); 
        } else {
            header("Location: http://50.22.79.62/~pftech/nationwide/");
        }
    }
    exit;
?>
4

1 回答 1

0

从您的 HTML 表单中:

<input name="home" type="radio" id="homeradio" />
...
<input name="home" type="radio" id="officeradio" />

您的单选按钮没有 value 属性。尝试类似:

<input name="home" type="radio" value="homeradio" />
...
<input name="home" type="radio" value="officeradio" />

然后在你的 PHP 中:

if($_GET["home"] == "homeradio") { 
    // home URLs here
    $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
    $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
    $urls[] = "http://50.22.79.62/~pftech/office-delivery/";
} elseif($_GET["home"] == "officeradio") { 
    // office URLs here
    $urls[] = "http://50.22.79.62/~pftech/water-delivery-service/";
    $urls[] = "http://50.22.79.62/~pftech/coffee-delivery/";
    $urls[] = "http://50.22.79.62/~pftech/water-filtration-systems/";
} else {
    // any other options can go here
}
于 2013-04-18T15:48:25.333 回答