Home > Backend Development > PHP Tutorial > Complete Example of PHP Determining the Selected Status of a Form Checkbox_PHP Tutorial

Complete Example of PHP Determining the Selected Status of a Form Checkbox_PHP Tutorial

WBOY
Release: 2016-07-13 10:26:06
Original
822 people have browsed it

Check boxes are often used in web forms, so how to use PHP to determine which check boxes are selected in the submitted form and read the data in them.

First create a form: form.html

Copy code The code is as follows:

3

7

1

15



Then create a program to process the form: checkbox.php

Copy code The code is as follows:
$a=$_POST["s"];
print_r($a);
?>


This can be displayed in the form of an array, which ones are selected. The display result is similar to: Array( [0]=7 [1]=15 )

But the above program is only used to display whether the check box is normal. If you take out all the data in the array one by one, you need to use a loop.

So further modify the program to: checkbox.php

Copy code The code is as follows:

$a=$_POST["s"];
for($i=0;$i {
echo "option".$a[$i]."selected
";
}
?>


The result of this execution is similar to:

Copy code The code is as follows:
Option 3 is selected
Option 15 is selected

I believe it will be much more convenient to execute other statements specifically in the next step.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824834.htmlTechArticleCheck boxes are often used in web forms, so how to use PHP to determine which check boxes are in the submitted form? is selected and the data in it is read. First create a form: form.html complex...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template