PHP checkbox values get output methods with checkbox default values
- 2020-03-31 20:45:36
- OfStack
PHP method to get the value of the checkbox checkbox
The checkbox USES an array when PHP reads the values, so we're going to read the values and we're going to use PHP post to get them as an array,
PHP checkbox selects questions by default (both using this principle)
<html xmlns="//www.jb51.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php To obtain checkbox Method of checkbox values </title>
</head>
<body>
<form name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value=" Check a ">
Check a
</label>
<label>
<input type="checkbox" name="checkbox[]" value=" Check the second ">
</label>
Check the second
<label>
<input type="checkbox" name="checkbox[]" value=" Check the three ">
</label>
Check the three
<label>
<input type="checkbox" name="checkbox[]" value=" Check for four ">
</label>
Check for four
<label>
<input type="submit" name="Submit" value=" submit ">
</label>
</form>
</body>
</html>
<?
if( $_POST )
{
$value = $_POST['checkbox'];
echo ' You have chosen :'.implode(',',$value);
// Due to the checkbox Properties, we have to take checkbox The name of the complex selection box is set to an if checkbox[] So that the php To read, in the form of data , Otherwise it cannot be read correctly checkbox Check box values. // The home of the script jb51.net finishing
}
?>
The checkbox USES an array when PHP reads the values, so we're going to read the values and we're going to use PHP post to get them as an 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 Gets multiple checkboxes checkbox value </title>
</head>
<body>
<?php
$area_arr = array();
if($_GET['action']=="submit"){
$area_arr = $_POST['area'];
}
echo " The area you selected is : ";
foreach ($area_arr as $k=>$v){
echo $v." ";
}
?>
<form id="form1" name="form1" method="post" action="?action=submit">
<p> hebei
<label>
<input type="checkbox" id="area" name="area[]" value=" hebei ">
</label>
</p>
<p> henan
<label>
<input type="checkbox" id="area[]" name="area[]" value=" henan ">
</label>
</p>
<p> shanxi
<label>
<input type="checkbox" id="area[]" name="area[]" value=" shanxi ">
</label>
</p>
<p> shandong
<label>
<input type="checkbox" id="area[]" name="area[]" value=" shandong ">
</label>
</p>
<p> jiangsu
<label>
<input type="checkbox" id="area[]" name="area[]" value=" jiangsu ">
</label>
</p>
<p> zhejiang
<label>
<input type="checkbox" id="area[]" name="area[]" value=" zhejiang ">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value=" submit ">
</label>
</p>
</form>
</body>
</html>
PHP checkbox selects questions by default (both using this principle)
<input name="jb51" type="checkbox" value="jiaju" <?php if($myrow[fujia_jiaju]) echo("checked");?>>