Re: error checking a null array

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

 



>From what I understand the simplest solution here would be to check to see 
if you have $_POST['cb'] in the first place.  That would indicate if 
checkbox was selected or not.  After, you have posted the form just do the 
following test.

$check_box_exits = ((isset($_POST['cb']))? true:false);

hope this helps...

-sonu

"Jack Jackson" <jackson.linux@xxxxxxxxx> wrote in message 
news:42EDA6B7.2090701@xxxxxxxxxxxx
> 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?
>
> Dump of $_POST with no checkboxes checked
> $_POST:
> array(4) { ["action"]=> string(7) "process" ["cat"]=> string(1) "2" 
> ["rs"]=> array(3) { [5]=> string(0) "" [6]=> string(0) "" [9]=> string(0) 
> "" } ["b"]=> string(8) "Continue" }
>
> Dump of $_POST with checkboxes checked
>
> array(5) { ["action"]=>  string(7) "process" ["cat"]=>  string(1) "2" 
> ["cb"]=>  array(2) { [7]=>  array(5) { [0]=>  string(1) "3" [1]=> 
> string(3) "124" [2]=>  string(3) "125" [3]=>  string(3) "127" [4]=> 
> string(3) "131" } [8]=>  array(3) { [0]=>  string(3) "141" [1]=> string(3) 
> "145" [2]=>  string(1) "4" } } ["rs"]=>  array(3) { [5]=> string(0) "" 
> [6]=>  string(0) "" [9]=>  string(0) "" } ["b"]=> string(8) "Continue" }
>
>
> Thanks so much 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