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 CopyCode The 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 code The 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>

default selection of PHP checkbox (this principle is used) copy Code the code is as follows: >

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.