How to get radio button's value in php | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to get radio button's value in php

Hi friends, I have a form in HTML that has a few radio buttons. I want to get the value of the radio button selected by the user. How can I do this in PHP?

17th Aug 2020, 9:28 PM
Morteza R.g
Morteza R.g - avatar
2 Answers
+ 2
Be sure to specify the name parameter in the form. For example, <input name="YOUR_RADIO_BUTTON_NAME" type="radio" value="1"> $_GET['YOUR_RADIO_BUTTON_NAME'] will work if your form's method is get. $_POST['YOUR_RADIO_BUTTON_NAME'] will work if your form's method is post. $_REQUEST['YOUR_RADIO_BUTTON_NAME'] will work regardless but it can be a little ambiguous.
17th Aug 2020, 9:34 PM
Josh Greig
Josh Greig - avatar
0
Adding to Josh Greig, set 'name' atribute values of all the radio button in a group to a unique name. <input type="radio" name="colour" value="Red" /> <input type="radio" name="colour" value="Green" /> <input type="radio" name="colour" value="Blue" />
18th Aug 2020, 2:41 AM
Ipang