PHP Gets the value of the form table's Select button and check box

Source: Internet
Author: User
get the value of a radio button

In the <form> form, radio button Radio is typically a group of groups that appear with the same name value and different value values, and in a group of radio buttons, only one of them may be selected at the same time.

To give an example of a radio button radio, there are two radio buttons for name = "Sexy" In this code instance, selecting one and clicking the Submit button returns the value of the selected radio button.

The specific development steps are as follows:

(1) Use any one of the development tools to create a PHP dynamic page and name it index.php.

(2) Add a form, add a set of radio buttons, and a Submit button, as shown in the following code:

<! DOCTYPE html>

Description: The Checked property is used to set the default meaning of the form element, and when the form page is initialized, the table cell element with the Checked property is selected.

(3) Add the PHP marker symbol anywhere outside the <form> form element, then apply the $_post[] global variable to get the value of the radio button group, and finally output it through the Echo statement, whose code is shown below:

<?php echo "The gender of your choice is:";                   Output string echo $_post["sexy"];                      Outputs the value of the selected radio button?>

(4) Enter the running address in the browser and press ENTER to get the result as shown:

Gets the value of the check box

check box to make multiple selections of items. When a browser fills out a form, it is necessary to select multiple items. For example, to listen to songs in the online need to select more than one song, etc., you will use the check box. Check boxes are generally multiple options exist at the same time, in order to facilitate the transfer of values, the name of name can be an array form, the format is:

<input type = "checkbox" Name= "checkbox[]" value= "CheckBox1" >

Return to the page you can use the count () function to calculate the size of the array, combined with the FOR Loop statement, to output the selected check box value.

Here is an example of the value of the Get check box, where a set of information is provided for the user to select, where the name value is mrbook[] array variable. Displays the user selected information on the processing page, and returns "You have not selected" if the array is empty, and the following code displays:

(1) Create a new index.php page that creates a form form, adds a set of check boxes, and a Submit button, as shown in the following code:

<! DOCTYPE html>

(2) Add a PHP marker anywhere outside of the <form> form element, then use the $_post[] global variable to get the value of the check, and finally output through the Echo statement, with the code shown below:

<?phpif ($_post["Mrbook"]!= null) {                       //judging check box if it is not empty, perform the following Operation   echo "The result you selected is:";                         Output string   for ($i = 0; $i < count ($_post["Mrbook"]), $i + +) {  //output The value of the selected check box through the FOR Loop statement      Echo $_post["Mrbook"] [$i ]." &nbsp; ";                Cycle output User-selected book category   }}?>

(3) Enter the running address in the browser and press ENTER to get the result as shown:

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.