Results 1 to 9 of 9

Thread: Checkbox?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Checkbox?

    How can you tell the value of a checkbox in PHP?

    if ($_REQUEST['mybox'] == ??)

    Thanks in advance.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Nevermind, this works:

    if (isset($_REQUEST['mybox']))
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    so if the checkbox isnt ticked then it just wont get the variable and gives a "false" or "0" value ?

  4. #4

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    huh? if the checkbox isn't checked, the variable isn't created, hence, not being set?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    thats basically what i was getting at

  6. #6
    New Member
    Join Date
    Jul 2001
    Posts
    14
    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.

  7. #7
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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 ).
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  8. #8
    scoutt
    Guest
    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

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Thanks, but I've already answered my own question...
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width