用慣Java和其他語言的時候,表單上傳只需要checkbox的name相同的時候就可以上傳了
<input type="checkbox" name="checkbox" value="1"> 選項<input type="checkbox" name="checkbox" value="2"> 選項<input type="checkbox" name="checkbox" value="3"> 選項<input type='button' value='確定' onclick="fun()"/>
但是PHP卻只有在這種情況下,name要寫成數組形式才能正常表單提交
<input type="checkbox" name="checkbox[]" value="1"> 選項1<input type="checkbox" name="checkbox[]" value="2"> 選項2<input type="checkbox" name="checkbox[]" value="3"> 選項3<input type="checkbox" name="checkbox[]" value="4"> 選項4<input type="checkbox" name="checkbox[]" value="5"> 選項5<input type="checkbox" name="checkbox[]" value="6"> 選項6<input type='button' value='確定' onclick="fun()"/>
下面給大家補充PHP處理Checkbox復選框表單提交問題
PHP表單提交頁面復選框的名稱后要加[],這樣在接收頁面才能得到正確的結果。表單提交后得到的是一個數組,然后通過訪問數組元素得到表單的具體vaule值。得到的checkbox1的值,默認有</br>換行。
表單代碼:
<form action="" method="post" name="asp"> 復選框1:<input type="checkbox" name="checkbox1[]" value="1" /> 復選框2:<input type="checkbox" name="checkbox1[]" value="2" /> 復選框3:<input type="checkbox" name="checkbox1[]" value="3" /> <input type="submit" name= "Download" vaue="Download" /> </form>
PHP處理表單代碼:
<?php    if(isset($_POST["Download"]))    {      foreach($_REQUEST['checkbox1'] as $checkbox1)      {           echo $checkbox1;      }    } ?> 以上所述是小編給大家介紹的PHP中CheckBox多選框上傳失敗的代碼寫法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
新聞熱點
疑難解答
圖片精選