Below we summarize the information about whether the check box in PHP is selected and written to the database.
Form.html
The code is as follows |
Copy Code |
|
Then create a program to process the form:
checkbox.php
The code is as follows |
Copy Code |
$a =$_post["s"]; Print_r ($a); ?> |
However, the above program is only used to show whether the check box is normal, if you remove all the data in the array, you need to use the loop.
So the program is further modified to:
checkbox.php
The code is as follows |
Copy Code |
$a =$_post["s"]; for ($i =0; $i { echo "Options". $a [$i]. " is selected "; } ?> |
The result of this execution is similar to the following:
Option 3 is selected
Option 15 is selected
Use JavaScript to do preprocessing. More than one check box with the same name exists in JavaScript or as an array, so you can use JavaScript to synthesize a character array from a check box to a hidden element in the form before the form is submitted, and then use the Explode function in PHP to parse the array. This enables the delivery of the check box information. The following examples illustrate.
Suppose you have a form like this:
The code is as follows |
Copy Code |
|
This form has a check box with four names that are item, and when the user clicks the Submit button, the checker function is called, and if Checker returns True, the form is committed, and the return false form is not committed. Here the checker function is the preprocessing function we are going to write. Add the following JavaScript in the header section of the HTML:
The code is as follows |
Copy Code |
|
http://www.bkjia.com/PHPjc/629008.html www.bkjia.com true http://www.bkjia.com/PHPjc/629008.html techarticle below we summarize the information about whether the check box in PHP is selected and written to the database. Form.html code as follows copy code form action=checkbox.ph ...