Null value / non checked chexkbox value posting problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ahmurad
    New Member
    • Aug 2007
    • 19

    Null value / non checked chexkbox value posting problem

    Dear all,
    I am fresh php programmer. I've spent much time to solve a checkbox related null value submission problem in php platform.

    I want to submit 4 checkbox value. if I checked all the checkbox, all the checked value is submitted properly. if checked any checkbox , the corresponding checkbox value is submitted properly.

    But I need to send the non checked value (please let non checked value is N ) with the checked checkbox value.

    Please run the following php code.

    [CODE=php]

    <html>
    <head>
    <title>checkb ox help</title>
    </head>
    <?

    if (isset($HTTP_PO ST_VARS)) {

    $fruit = $HTTP_POST_VARS["fruit"];

    echo("Fruits chosen: " . count($fruit) . "<br><br>") ;

    if (count($fruit)> 0) {
    echo("You chose the following fruits:<br>");
    }

    for ($i=0; $i<count($fruit ); $i++) {
    echo( ($i+1) . ") " . $fruit[$i] . "<br>");
    }
    }
    ?>
    <body bgcolor="#fffff f">

    <form method="post">
    Choose a fruit:<br><br>
    <input type="checkbox" name="fruit[]" value="apples"> apples <br>
    <input type="checkbox" name="fruit[]" value="oranges" >oranges <br>
    <input type="checkbox" name="fruit[]" value="peaches" >peaches <br>
    <input type="checkbox" name="fruit[]" value="mangos"> mangos<br>
    <input type="submit">
    </form>

    </body>
    <html>

    [/CODE]

    Expected Output:
    Suppose you check 1 and 3 checkbox. the output wil be:

    You chose the following fruits:
    1) apples
    2 N
    3) peaches
    4) N

    Suppose you check none of the checkboxes . the output wil be:
    1) N
    2) N
    3) N
    4) N

    Related help is highly appreciated and thanks to all.

    AHM
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    First of all, the $HTTP_POST_VARS array is deprecated and should not be used. Use the $_POST super-global instead.

    Checkboxes will not be included in the POST data if they are not check, as I think you know. So the only way to really do what you ask is to either:
    A. Send each checkbox with its own name and check which of them were sent in your PHP code, or
    B. Send them all in an array and check which values you are getting in your PHP code.

    Comment

    • ahmurad
      New Member
      • Aug 2007
      • 19

      #3
      Thanks for your proper guide.

      is there any help so that when any checkbox is remaining to select then will crete a warning message specifying the related checkbox number.

      Comment

      Working...