$var update in index.php after returning from performing func

14 views
Skip to first unread message

Jeff Newman

unread,
Mar 7, 2011, 8:20:08 AM3/7/11
to php...@googlegroups.com
Using the "func" variable, you can perform functions on input and perform
page logic accordingly. However, the way the index.php file is currently
organized, if you change any of the supplied values passed in, they aren't
available to the rest of the page after that input is processed.

For example, say you have three required fields, and your submit function
checks to make sure they are all properly capitalized, then checks to make
sure they are all filled in (order doesn't matter, but for the sake of
argument...). if you "fail" the function because of the missing field data,
but want to retain the upper casing, it won't. the $vars are processed into
$keys prior to the function call, so any changes to them aren't retained
after the failed function call.

To get around this, you can add this chuck of code after the SWITCH that
performs the func calls:

if (count($vars)){
while (list($key, $value) = each ($vars))
$$key = harden_parse($vars[$key]);
}

I put it inside the "if ($func)" check, just to make sure it's not running
extra.

This is identical to what was done prior (and it still checks for inserted
no-no's), but updates the $key values with the data that you might have
changed or creates $key values for the ones you created (and might want to
retain) during the function processing.

This would explain why, if you set the $d["error"] key to an error message
inside a function, it wouldn't get displayed when you failed back out of
that function, because the $error key wasn't getting updated after the call.
You had to refer directly to $vars["error"] in the error.php file to get it
to display that message correctly (which has been a bug in that page for a
LONG time).

Not that anyone really cares, but just making a note of it...

Jeff Newman

Reply all
Reply to author
Forward
0 new messages