2012-04-30 71 views
1

我試着讓表單提交值,如果他們符合某種條件重定向只有我的網頁似乎沒有...如果POST變量等於然後重定向

我有多個輸入字段

形式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/'); 
    } 
+1

什麼在下降? –

+0

它沒有重定向,也沒有迴應我的警報@Truth – Liam

+0

您是否嘗試在if行失敗時打印出if行的變量? – Nobody

回答

3

你的一個條件正在下降(因爲它們都受AND約束,所有的if語句都失敗了。

有一個else語句,你var_dump所有相關的變量,看看有什麼不對。

0

對不起,大家,我的監督下,我正在檢查是否發佈了錯誤的變量,如果不是建議添加其他語句,不會發現它,謝謝!