2014-04-27 30 views
0

所以這是我的問題。我有以下形式:Firefox nad IE窗體沒有提交正確

<form name="picture_categories" action="scripts/catalog.php" method="post"> 
      <input class="visibleForm" onclick="return false;" type="image" src="images/smartphones.png"/> 
      <label for="smartphones">Smartphones</label> 
      <input type="hidden" name="device" value="smartphones" /> 
      <div class="hiddenForm" style="display:none"> 
       <input src="images/logos/apple-logo.png" type="image" name="manuf" value="APPLE" /> 
       <input src="images/logos/samsung-logo.png" type="image" name="manuf" value="Samsung" /> 
       <input src="images/logos/blackberry-logo.png" type="image" name="manuf" value="Blackberry" /> 
       <!-- <input src="images/logos/htc_logo.png" type="image" name="manuf" value="HTC" /> add to catalog first--> 
       <input src="images/logos/lg-logo.png" type="image" name="manuf" value="LG" /> 
      </div> 
    </form> 

推測,當我點擊的輸入[名稱=「MANUF」]它與隱藏的輸入(「設備」)值設置到下頁沿submitts其值之一。 現在,下一個頁面下面的腳本:

<?php session_start(); ?> 
<?php 
    if(isset($_POST['device'])) { 
     $_SESSION['device'] = $_POST['device']; 
     } 
    if (isset($_POST['manuf'])) { 
     $_SESSION['manuf'] = $_POST['manuf']; 
     } 

     header ("Location: ../display_catalog.php"); 
?> 

而且最後一頁 - display_catalog.php使用$ _SESSION的數據顯示目錄的相關部分。

該代碼在Chrome中非常出色;然而:

  • 在Firefox以某種方式忽略$ _SESSION ['manuf']變量。所以它通過$ _SESSION ['device']正確地對我的目錄進行排序,但不想按製造商名稱排序。
  • 在IE中,它完全忽略了兩個$ _SESSION變量。

這裏有什麼問題?

回答

1

這是因爲輸入按鈕的類型圖像carry the x,y coordinate of the button,而不是價值(該按鈕用於使圖像作爲提交)。它的行爲非常依賴於瀏覽器,這就是爲什麼你看到它在瀏覽器中運行如此不同的原因。

如果你想用影像來定製,並有一個提交按鈕正常工作,你可以使用<button>元素和風格也與CSS背景屬性,或者直接把一個img元素:

喜歡的東西:

<button type="submit" name="manuf" value="apple"><img src="apple-image.png"></button> 
<button type="submit" name="manuf" value="samsung"><img src="somsung-image.png"></button> 
+0

謝謝。現在就像魅力一樣。 –