Get the checkbox value of the PHP checkbox and the checkbox default value Output Method _php Foundation

Source: Internet
Author: User
how PHP gets checkbox values for checkboxes
Copy Code code as follows:

<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>php method to get CheckBox value </title>
<body>
<form name= "Form1" method= "Post" action= "" >
<label>
<input type= "checkbox" Name= "checkbox[]" value= "Check One" >
Check A
</label>
<label>
<input type= "checkbox" Name= "checkbox[]" value= "Check Two" >
</label>
Check Two
<label>
<input type= "checkbox" Name= "checkbox[]" value= "Check three" >
</label>
Check Three
<label>
<input type= "checkbox" Name= "checkbox[]" value= "Check Four" >
</label>
Check Four
<label>
<input type= "Submit" name= "Submission" value= "submitted" >
</label>
</form>
</body>
?
if ($_post)
{
$value = $_post[' checkbox '];
Echo ' You chose: '. Implode (', ', $value);
Because of the checkbox properties, we must set the checkbox's name to one if checkbox[] so that PHP can read it in data form, otherwise it cannot correctly read the CheckBox checkbox value OH. Jb51.net finishing of cloud-dwelling community
}
?>


checkbox in PHP to read the value in the array form Oh, we read these values in PHP post fetch is in an array form Oh,
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title>php Get checkbox value for multiple marquee </title>
<body>
<?php
$area _arr = Array ();
if ($_get[' action ']== "submit") {
$area _arr = $_post[' area '];
}
echo "Your chosen area 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= "Submission" value= "submitted" >
</label>
</p>
</form>
</body>

The php checkbox defaults to the problem (which is the principle used)
Copy Code code as follows:

<input name= "jb51" type= "checkbox" value= "Jiaju" <?php if ($myrow [Fujia_jiaju]) echo ("checked");? >>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.