Re: need loop help

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

 



On 10/3/06, Charles Kline <ckline@xxxxxxxxxxxxx> wrote:
hi all.

i am trying to modify some old code and struggling a bit with this one:

// returns an array of the names in the form post
$fields = $_SESSION['case']->getComplaintKeys();

First of all this is news to me, I'm not sure how it is that you're
getting the POST values from here.  But OK...


// here is the array returned
Array ( [0] => eligibility [1] => payment [2] => service [3] =>
document [4] => licensing [5] => source [6] => date [7] => contact
[8] => description [9] => status )

for ($j = 0; $j < count($fields); $j++) {
   if (${$fields[$j]} == 'on') ${$fields[$j]} = 1;
   if (is_null(${$fields[$j]})) ${$fields[$j]} = 0;
   $data[$fields[$j]] = ${$fields[$j]};
}


Well, I'd start off by *not* using this dynamic variable everywhere
(because it's hard to read and easy to introduce a bug), but just set
it to a temp variable and use that, like so:

for ($j = 0; $j < count($fields); $j++) {
 $myField = ${$fields[$j]};
 if($myField == 'on') $myField = 1;
 if(is_null($myField) $myField = 0;
 $data[$fields[$j]] = $myField;
}

The problem I am having is that the code is now on a more secure
server with register_globals off (and I don't want to turn that on).

I am not sure how to get the POST data sorted out using this method.
Hope it is clear what I mean.

Then if you need to explicitly reference the variable name within
POST, just change that line:

for ($j = 0; $j < count($fields); $j++) {
 $myField = $_POST[$fields[$j]];
 if($myField == 'on') $myField = 1;
 if(is_null($myField) $myField = 0;
 $data[$fields[$j]] = $myField;
}

Untested.  Does that work for you?

HTH,
John W


Thanks,
Charles

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



--
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