Re: Re: error checking a null array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





David Robley wrote:
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

I would have thought so too, but empty doesn't seem to work if it's not there at all, (I guess it figures, how can it be empty if it isn't there) and isset doesn't work if the array is there but null. or something like that. IN any case I've yet to get them working using either. I probably should have said that!

Thanks in advance

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux