1

我试图获取表单帖子值,如果它们符合某些条件,则仅重定向我的页面似乎不...

我有一个包含多个输入字段的表单

HTML

<form method="post" action="?page_id=151">

  <div style="display: block;" id="Q1">
                    <label for="vehicleType">1. What type of vehicles do you have?</label>
                    <select id="vehicleType" name="vehicleType">
                        <option selected="selected" value="choose">Please choose</option>
                        <option value="hgv">HGV</option>
                        <option value="psv">PSV</option>
                        <option value="lgv">LGV</option>
                        <option value="car">Car</option>                            
                        <option value="mixed">Mixed Fleet</option>
                    </select>
                </div>

                <div id="Q2group1">
                    <label for="coverageRegion">2. Do you require national or international coverage?</label>
                    <select id="coverageRegion" name="coverageRegion">
                        <option selected="selected" value="choose">Please choose</option>
                        <option value="national">National</option>  
                        <option value="international">International</option>
                    </select>
                </div>

                <div id="Q2others">
                    <label for="pricing">2. Do you prefer a fixed weekly price or a pump-related price?</label>
                    <select id="pricing" name="pricing">
                        <option selected="selected" value="choose">Please choose</option>
                        <option value="fixed">Weekly fixed price</option>  
                        <option value="pump">Pump-related price</option>
                    </select>
                </div>

                <div id="Q3group1">
                    <label for="locationType">3. What type of site do you prefer?</label>
                    <select id="locationType" name="locationType">
                        <option selected="selected" value="choose">Please choose</option>
                        <option value="truckstops">Truck stops at lowest price</option>  
                        <option value="motorway">Branded motorway sites</option>
                    </select>
                </div>


             <div id="Q3others">
                    <label for="siteCoverage">3. What site coverage do you need?</label>
                    <select id="siteCoverage" name="siteCoverage">
                        <option value="choose">Please choose</option>
                        <option value="countysites">County</option>
                        <option value="nationalsites">National</option>
                    </select>
                </div>


                <div id="Q4others">
                    <label for="county">4. Select your county:</label>
                    <select id="county" name="county">
                        <option value="choose">Please choose</option>
                        <optgroup label="England">
                            <option>Bedfordshire</option>
                            <option>Berkshire</option>
                            <option>Bristol</option>
                            <option>Tyrone</option>
                        </optgroup>
                    </select></div>

                <div id="searchbuttondiv"> <input type="submit" id="searchbutton" onclick="_gaq.push(['_trackEvent', 'Fuel Card Search', 'Homepage Select Criteria'])">    </div>   

            </form>

PHP

if ($_POST['vehicleType'] == 'car' && $_POST['pricing'] == 'fixed' && $_POST['coverageRegion'] == 'national') {
        echo '<script>alert("hi");</script>';
        // header('Location: /car-weekly-national/');
    }
4

2 回答 2

3

您的条件之一是下降(并且因为它们都受 AND 约束,所以所有 if 语句都失败了。

有一个 else 语句,你 var_dump 所有相关变量,看看有什么问题。

于 2012-04-30T08:33:40.110 回答
0

对不起大家,我的疏忽,我正在检查是否发布了错误的变量,如果不是为了添加else语句的建议,我不会找到它,谢谢!

于 2012-04-30T08:46:47.590 回答