How to get radio button's value in php | SoloLearn: Learn to code for FREE!

+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?

8/17/2020 9:28:36 PM

Morteza R.g

2 Answers

New Answer

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

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" />