+ 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?
2 ответов
+ 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" />