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.) )

Example: <form name= "MyForm" action= "" method= "POST" >

Gender:

<input type= "Radio" name= "Sex" value= "male" checked/> male <input name= "Sex" type= "Radio" value= "female"/> Female

<input type= "Submit" name= "Submit" value= "Submission"/>

</form>

<?php

echo "Your choice is:";

echo $_post["Sex"];

?>

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.

Example: <form action= "" Name= "Form1" method= "POST" >

The number you like:

<input type= "checkbox" Name= "mrbook[]" value= "1"/>1

<input type= "checkbox" Name= "mrbook[]" value= "2"/>2

<input type= "checkbox" Name= "mrbook[]" value= "3"/>3

<input type= "checkbox" Name= "mrbook[]" value= "4"/>4

<input type= "Submit" name= "Submit" value= "Submission"/>

</form>

<?php

if ($_post[' Mrbook ']!=null)

{

echo "The number you selected is:";

for ($i =0; $i <count ($_post[' Mrbook '); $i + +)

{

echo $_post[' Mrbook ' [$i]. " &nbsp;&nbsp; ";

}

}

?>

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

Related Article

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.