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??
Selecting values from radio field
Moderator: General Moderators
-
phpCCore Brad
- Forum Commoner
- Posts: 47
- Joined: Sun Dec 04, 2005 5:46 pm
- Location: Michigan, USA
- Contact:
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- technofreak
- Forum Commoner
- Posts: 74
- Joined: Thu Jun 01, 2006 12:30 am
- Location: Chennai, India
- Contact:
Why don't you just use $_POST than using $_REQUEST ?
The code will be then...
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 
The code will be then...
Code: Select all
if ($_POST['yesorno'] == 'yes') {
<code>
} elseif ($_POST['yesorno'] == 'no') {
<code>
}-
phpCCore Brad
- Forum Commoner
- Posts: 47
- Joined: Sun Dec 04, 2005 5:46 pm
- Location: Michigan, USA
- Contact:
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!
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!