How can you tell the value of a checkbox in PHP?
if ($_REQUEST['mybox'] == ??)
Thanks in advance.
Printable View
How can you tell the value of a checkbox in PHP?
if ($_REQUEST['mybox'] == ??)
Thanks in advance.
Nevermind, this works:
if (isset($_REQUEST['mybox']))
so if the checkbox isnt ticked then it just wont get the variable and gives a "false" or "0" value ?
huh? if the checkbox isn't checked, the variable isn't created, hence, not being set?
thats basically what i was getting at :p
If you have a single checkbox on your form you can simply use the name of the checkbox as a variable that stores the data in it. So in your example you can use $mybox to get the value of the checkbox. This can be used to all other form controls.
If you have multiple checkboxes. Lets say you ask the user to choose their favorite color among some colors that you have on your form, the best way is to name your checkboxes something like "fav_colors[]". This way your script is going to receive the information of the checkboxes in an array and can use the data as $fav_colors[0],$fav_colors[1],etc...
The values on the array are only the values of the checkboxes that were checked. If a checbkbox is not checked the script does not receive it value.
ahh, but by 4.2 standards register_globals is off so you cannot just use $mybox you have to use either of the following based on your form's method setting:
$_POST['mybox']
$_GET['mybox']
or you can use $_REQUEST['mybox'] which works in most cases (i have had troubles with $_REQUEST[] recently :().
I have had just the opposite Matt, I have had problems with $_POST and not $_REQUEST
curious as to what problems you have been having? you can pm me if you want over this so we don't disrupt Hobo and his post :)
Thanks, but I've already answered my own question...:rolleyes: