Results 1 to 6 of 6

Thread: Radio Buttons and Checkboxes Not posting

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    51

    Radio Buttons and Checkboxes Not posting

    Hello everyone,

    I am hoping some PHP expert out there can help this newbie with the problem I am having.

    I have a form with textfields, checkboxes, and radio buttons. These value are submitted using the POST method to another php page. The problem is if a checkbox is not checked or a radio button in a group is not selected, then nothing shows up in the corresponding $_POST array. By nothing I mean the checkbox or radio button name is not present in the array. I don't understand this.

    Here is how I am creating the checkboxes and radio buttons.

    <INPUT type=RADIO name=\"q1\" value=\"2\">2

    <INPUT type=RADIO name=\"q20\" value=\"Yes\">Yes

    Any help with this problem would be greatly appreciated.

  2. #2
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    That is how radio buttons and checkboxes work, if they are checked/selected they are present in $_POST/$_GET, otherwise they are not.

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    51
    Thanks twanvl,

    I have found a way to get around the problem. I have another question though. I need to know when a textarea comes in empty. What is the value of an empty textfield? I have tried using "" and NULL, but that doesnt seem to work.

    if ($temp != NULL) {
    print $temp;
    }

    Still prints

    Thanks

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    if a textarea is empty it's value should =="" and also ==="". How can you see that it prints if it prints an empty string?

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2004
    Posts
    51
    Hi twanvl,

    I can't actually see the empty string printing, but the value for the field is printing. The field name is only supposed to show up if there is an entry.

    (like this)

    Field Name: "The field text"

    if there is no text in the field then I should get nothing, but instead I get

    Field Name: <nothing>

    I have found a work around though. Instead of checking for "" or null, I just check to see if the length of the string is equal to 0.

    Thanks for all of your help

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    If you want to force a value for a particular field, use a hidden input tag.
    Code:
    <input tyoe="hidden" name="q1" value="undefined" />
    <input type="radio" name="q1" value="2">2
    
    <input type="radio" name="q20" value="Yes">Yes
    If the use doesn't select a radio button, then the hidden field value provails and gets sent through, if they do, the value of the radio button selected is submitted instead.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

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