Re: error checking a null array

From: Date: Mon, 01 Aug 2005 05:18:50 +0000
Subject: Re: error checking a null array
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-219733@lists.php.net to get a copy of this message
Jack Jackson wrote: > hi, > I have checkboxes beging dynamically generated. to seperate tasks in > error checking I have added he arrays not just to $_POST but to > $_POST[cb] so names (derived from question numbers) are for example: > > $_POST[cb][7] > > A dump of $_POST would therefore include something like > > ["cb"]=> array(1) { [7]=> array(1) { [0]=> string(3) "124" } } > > So I did this: > > //error checking for checkboxes > foreach ($cb as $cbkey => $cbvalue) > { > foreach($cbvalue as $cbkey2=>$cb_answers) > { > if( !array_key_exists($_POST[$cbkey], $cb)); > { > $message[$cbkey]=1; > } > } > } > > This almost works. The problem is that if someone doesn't check a > checkbox, NOTHING related to the checkbox gets sent to $_POST; if I > insert a hidden value of something, then that hidden value gets passed > whether the user inputs something or not, since I need an entirely > server-side solution. Is there a way to send something to tell the error > checker whether for example $_POST[cb][7] is empty or null, so I can set > the error message to one if it's empty? I think you might find empty() and isset() fairly useful here. Cheers -- David Robley Don't play stupid with me! I'm better at it.

« previous php.general (#219733) next »