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.
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>checkbox help</title>
- </head>
- <?
- if (isset($HTTP_POST_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="#ffffff">
- <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>
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