Chris Grigor wrote:
Hi Chris

While this works, it only posts the checkboxes that have been selected. How would I get a list of ones not checked?

Always reply to the list as well.


Checkboxes aren't submitted if they are not checked. It's not a PHP thing that does this.


That's why you have to check it this way.


..... if it's in the post array, it was checked.
if (isset($_POST['blah'][$p])) {
.....
}

..... if it's not in the post array, it was not checked.
if (!isset($_POST['blah'][$p])) {
.....
}


notice the isset and !isset (not isset).


Chris wrote:

Chris Grigor wrote:

morning all,

Is there an easier way of doing the following??

form1 submitting to form1.php
<input type="checkbox" name="1">
<input type="checkbox" name="2">
<input type="submit>



make this into:

<input type="checkbox" name="blah[1]" value="1">
<input type="checkbox" name="blah[2]" value="1">

then you can:

foreach($_POST['blah'] as $p => $x) {
  if (!isset($_POST['blah'][$p])) {
   echo "item $p was not selected";
  } else {
   echo "item $p was selected";
  }
}





--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to