Re: Is there an easier way of doing this?

From: Date: Wed, 10 May 2006 09:26:15 +0000
Subject: Re: Is there an easier way of doing this?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-235868@lists.php.net to get a copy of this message
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/

« previous php.general (#235868) next »