How to get the value of a radio button and a check button in a php form

Source: Internet
Author: User
Tags php form

The PHP code gets the value of the radio button in the form: (The radio button lets us select only one, there is a "checked" property, which is used by default, which is the default value each time we refresh our page.) )

Cases:

1 <formname= "MyForm"Action=""Method= "POST">2 Gender:3 <inputtype= "Radio"name= "Sex"value= "Male"checked/>male4 <inputname= "Sex"type= "Radio"value= "female" />female5 <inputtype= "Submit"name= "Submit"value= "Submit" />6 </form>
1 <? PHP 2 Echo "Your choice is:"; 3 Echo $_post ["Sex"]; 4 ?>

If you choose a male, then the value is "male", if you choose a female, then the value is "female."

The PHP code gets the value of the check box : (check box is able to let us go to the multi-select, they exist at the same time, in order to facilitate the value we will name to an array.) )

Format: <input type= "checkbox" Name= "chkbox[]" value= "Chkbox1"/>

Method: The Count () function is used in the return page to calculate the size of the array, combined with a For loop statement, to output the selected check box value.

Cases:

1 <formAction=""name= "Form1"Method= "POST">2 the number you like:3 <inputtype= "checkbox"name= "mrbook[]"value= "1" />14 <inputtype= "checkbox"name= "mrbook[]"value= "2" />25 <inputtype= "checkbox"name= "mrbook[]"value= "3" />36 <inputtype= "checkbox"name= "mrbook[]"value= "4" />47 <inputtype= "Submit"name= "Submit"value= "Submit" />8 </form>
1<?PHP2 if($_post[' Mrbook ']!=NULL)3 {4        Echo"The number you selected is:";5         for($i= 0;$i<Count($_post[' Mrbook ']);$i++)6        {7               Echo $_post[' Mrbook '] [$i]." &nbsp;&nbsp; ";8        }9 }Ten?>

How to get the value of a radio button and a check button in a php form

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.