phpはcheckboxチェックボックスの内容をどのように取得しますか?

4362 ワード

     checkbox  ,     checkbox              checkbox[],php    ,     ,         checkbox      。



<form name="form1" method="post" action="">

<label><input type="checkbox" name="checkbox[]" value="   "></label>

<label><input type="checkbox" name="checkbox[]" value="   "></label>   

<label><input type="checkbox" name="checkbox[]" value="   "></label>   

<label><input type="checkbox" name="checkbox[]" value="   "></label>   



 



<label><input type="submit" name="Submit" value="  "></label>

</form>

<?php

if( $_POST )

{

$value = $_POST['checkbox'];

echo '    :'.implode(',',$value);

}

?>

 
checkboxはphpで値を読み込むときに配列形式を使いますよ.これらの値をphp postで取得するのはarray形式ですよ.
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 

<title>php     checkbox </title> 

</head> 

<body> 

<?php 

$area_arr = array(); 

if($_GET['action']=="submit"){ 

$area_arr = $_POST['area']; 

} 

echo "       : "; 

foreach ($area_arr as $k=>$v){ 

echo $v." "; 

} 

?> 

<form id="form1" name="form1" method="post" action="?action=submit"> 

    

<label> 

<input type="checkbox" id="area" name="area[]" value="  "> 

</label> 

  

    

<label> 

<input type="checkbox" id="area[]" name="area[]" value="  "> 

</label> 

  

    

<label> 

<input type="checkbox" id="area[]" name="area[]" value="  "> 

</label> 

  

    

<label> 

<input type="checkbox" id="area[]" name="area[]" value="  "> 

</label> 

  

    

<label> 

<input type="checkbox" id="area[]" name="area[]" value="  "> 

</label> 

  

    

<label> 

<input type="checkbox" id="area[]" name="area[]" value="  "> 

</label> 

  

  

<label> 

<input type="submit" name="Submit" value="  "> 

</label> 

  

</form> 

</body> 

</html>