PHP checkbox values are specified
- 2020-03-31 21:07:10
- OfStack
Let's say we have an HTML page, the code is as follows:
Notice the name property of input above, each property has the same content, and it is all test[], the reason for adding [] is that the contents of the test are passed as an array.
The code for checktest.php is as follows:
All we need to do is use the implode function to turn the contents of the array into a string.
Note: this function can be used to delete multiple records and other occasions. Delete from TBL where ID in (implode(",",$_POST['test'])).
Example code:
<FORM method="post" action="checkTest.php">
<INPUT name="test[]" type="checkbox" value="1" />
<INPUT type="checkbox" name="test[]" value="2" />
<INPUT type="checkbox" name="test[]" value="3" />
<INPUT type="checkbox" name="test[]" value="4" />
<INPUT type="checkbox" name="test[]" value="5" />
<INPUT type="submit" name="Submit" value="Submit" />
</FORM>
Notice the name property of input above, each property has the same content, and it is all test[], the reason for adding [] is that the contents of the test are passed as an array.
The code for checktest.php is as follows:
<?php
echo implode(",",$_POST['test']);
?>
All we need to do is use the implode function to turn the contents of the array into a string.
Note: this function can be used to delete multiple records and other occasions. Delete from TBL where ID in (implode(",",$_POST['test'])).
Example code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title> Headless document </title>
</head>
<body>
html Check box if you want to send it as a data group to php Script processing must be like this checkbox[] This form
<form id="form1" name="form1" method="post" action="">
<label>
<input type="checkbox" name="checkbox[]" value="1" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="2" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="www.jb51.net" />
</label>
<label>
<input type="checkbox" name="checkbox[]" value="jb51.net" />
</label>
<label>
<input type="submit" name="Submit" value=" submit " />
</label>
</form>
</body>
</html>
<?
//Determine whether to click submit
if( $_POST )
{
$array = $_POST['checkbox'];
print_r($array);
}
?>