How to get the values of radio buttons and check buttons in php form (example)

PHPz
Release: 2023-03-07 09:44:01
Original
2012 people have browsed it

Get the value of the radio button in the form in the php code: (The radio button can only allow us to select one. There is a "checked" attribute here, which is used to select it by default. Every time we refresh our page It defaults to this value.)

Example:

Copy after login

Gender:

  
Copy after login

If you select male, the value that comes out will be "male". is female, the value that comes out is "female".

Get the value of the check box in the php code: (The check box allows us to select multiple times. They exist at the same time. In order to facilitate the transfer of values, we set the name to an array.)

The format is:

Copy after login

Method: Use the count() function to calculate the size of the array in the return page, and combine it with a for loop statement to output the value of the selected check box.

Example:

Copy after login

Your favorite number:

1 2 3 4   
Copy after login

We have to learn to use arrays to solve our problems! ! ! !

The above is the detailed content of How to get the values of radio buttons and check buttons in php form (example). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!