Page 1 of 1

Selecting values from radio field

Posted: Sun Jun 18, 2006 6:32 am
by mcccy005
I'm trying to determine the value submitted in a radio field but having a few problems for some reason.

I'm using a radio field with 2 options - Yes and No. (Yep, I know I really should use a checkbox for this, but a lot of the people who will use the website may be extremely computer illiterate and so black and white 'Yes' or 'No' is easier for them to understand than a checkbox!!)

Anyways....
If I get the value of the radio field using $_REQUEST[$field_name], the value is ALWAYS 'Yes' whether I select 'Yes' or 'No' in the radio field.
Even in the html code, the value of each radio option is correct!

Perhaps there's some alternate way to get the values??

Posted: Sun Jun 18, 2006 6:39 am
by printf
Can we see the HTML!

pif!

Posted: Sun Jun 18, 2006 10:21 am
by phpCCore Brad

Code: Select all

<input type="radio" name="yesorno" value="Yes">Yes 
<input type="radio" name="yesorno" value="No">No

//Should Yield

$_REQUEST["yesorno"] = "Yes"; //If the yes radio is clicked
$_REQUEST["yesorno"] = "No";  //If the no radio is clicked

Posted: Sun Jun 18, 2006 10:46 am
by technofreak
Why don't you just use $_POST than using $_REQUEST ?

The code will be then...

Code: Select all

if ($_POST['yesorno'] == 'yes') {

<code>

} elseif ($_POST['yesorno'] == 'no') {

<code>

}
In your code, you are trying to assign "yes" to the $_REQUEST variable in the first line and again trying to asign 'no" to the same variable. Think if you meaning to check the value there, please use "==" instead of "=". I have made the same mistakes and wondered why the if condition is not working :)

Posted: Sun Jun 18, 2006 10:58 am
by phpCCore Brad
I was just posting an example for him. That wasn't meant to be PHP it was meant to tell him would the $_REQUEST would be set to. And the reason I used $_REQUEST instead of $_POST is I have no idea if his form is get or post.

Posted: Sun Jun 18, 2006 11:05 am
by printf
Isn't guessing fun, :wink:

pif!

Posted: Mon Jun 19, 2006 6:48 am
by mcccy005
Was half way through writing back ("knowing" I woulnd't/couldnt have done anything as silly as missing out on double equals and um....well yeah.
Thanks - I have a bad habbit of doing stupid stupid little things in programs.

PS. The reason I always use $_REQUEST is because a lot of what I'm writing is objects which I will implement later for future projects and so it will allow me to use $_GET or $_POST.
Suppose I should research security issues relating to $_REQUEST though!