Php checkbox check box value acquisition and checkbox default value output method

Source: Internet
Author: User

Php method for obtaining the checkbox check box Value
Copy codeThe Code is as follows:
<Html xmlns = "http://www.jb51.net/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> php method for obtaining the checkbox check box value </title>
</Head>
<Body>
<Form name = "form1" method = "post" action = "">
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check">
Check item 1
</Label>
<Label>
<Input type = "checkbox" name = "checkbox []" value = "2">
</Label>
Check Option 2
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check three">
</Label>
Check 3
<Label>
<Input type = "checkbox" name = "checkbox []" value = "check box">
</Label>
Check item 4
<Label>
<Input type = "submit" name = "Submit" value = "submit">
</Label>
</Form>
</Body>
</Html>
<?
If ($ _ POST)
{
$ Value = $ _ POST ['checkbox'];
Echo 'you selected:'. implode (',', $ value );
// Because of the checkbox attribute, we must set the name of the checkbox re-selection box to one if checkbox [], so that php can read data in the form of data, otherwise, the value of the checkbox check box cannot be correctly read. // Tidy up jb51.net
}
?>


Checkbox should be in the array format when reading values in php. We can read these values using php post to get them as an array,
Copy codeThe Code is as follows:
<! 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 obtains the checkbox value of multiple selection boxes. </title>
</Head>
<Body>
<? Php
$ Area_arr = array ();
If ($ _ GET ['action'] = "submit "){
$ Area_arr =$ _ POST ['are'];
}
Echo "the region 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 default selection problem (this principle is used)
Copy codeThe Code is 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.