|
-
Jul 16th, 2002, 02:05 PM
#1
Thread Starter
Stuck in the 80s
Checkbox?
How can you tell the value of a checkbox in PHP?
if ($_REQUEST['mybox'] == ??)
Thanks in advance.
-
Jul 16th, 2002, 02:22 PM
#2
Thread Starter
Stuck in the 80s
Nevermind, this works:
if (isset($_REQUEST['mybox']))
-
Jul 16th, 2002, 06:21 PM
#3
Fanatic Member
so if the checkbox isnt ticked then it just wont get the variable and gives a "false" or "0" value ?
-
Jul 16th, 2002, 10:25 PM
#4
Thread Starter
Stuck in the 80s
huh? if the checkbox isn't checked, the variable isn't created, hence, not being set?
-
Jul 17th, 2002, 12:02 AM
#5
Fanatic Member
thats basically what i was getting at
-
Jul 17th, 2002, 01:01 AM
#6
New Member
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.
-
Jul 17th, 2002, 05:40 AM
#7
Fanatic Member
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 ).
-
Jul 17th, 2002, 11:48 AM
#8
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
-
Jul 17th, 2002, 09:00 PM
#9
Thread Starter
Stuck in the 80s
Thanks, but I've already answered my own question...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|