form data methods
| From: | Dan Allen | Date: | Sun, 09 Jun 2002 21:14:24 +0000 |
| Subject: | form data methods | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-6820@lists.php.net to get a copy of this message | ||
I would be very helpful if we had a class which had methods (or they
were bound with an already existing class) that handled form data in
the following way, similar to the code found in Horde's framework:
function getRequestData($in_var, $in_type = 'gpc', $in_default = null,
$in_stripSlashes = true,
$in_unserialize = false)
{
// I do this fancy stuff so that you can retrieve an element
// of an array by just typing getRequestData('foo[one][two]')
if ($pos = strpos($in_var, '[')) {
$var = '[' . substr($in_var, 0, $pos) . ']' . substr($in_var, $pos);
}
else {
$var = '[' . $in_var . ']';
}
switch (true) {
case stristr($in_type, 'p'):
if (eval("return isset(\$_POST$var);")) {
$data = $in_stripSlashes ? HTTP::disableMagicQuotes(eval("return
\$_POST$var;")) : eval("return \$_POST$var;");
break;
}
case stristr($in_type, 'g'):
if (eval("return isset(\$_GET$var);")) {
$data = $in_stripSlashes ? HTTP::disableMagicQuotes(eval("return
\$_GET$var;"))
: eval("return \$_GET$var;");
break;
}
case stristr($in_type, 'c'):
if (eval("return isset(\$_COOKIE$var);")) {
$data = $in_stripSlashes ? HTTP::disableMagicQuotes(eval("return
\$_COOKIE$var;")) : eval("return \$_COOKIE$var;");
break;
}
default:
break;
}
if (!isset($data)) {
return $in_default;
}
else {
return $in_unserialize ? unserialize($data) : $data;
}
}
Where natural disableMagicQuotes does the obvious check for
get_magic_quotes_gpc() and then strips them if they are found. This
way you can do
getRequestData('foo', 'gp', 'default');
Just a thought...I use it in my own code all the time.
Dan
--
________________________________________________________________
Daniel Allen, <dan@mojavelinux.com>
http://www.mojavelinux.com/
________________________________________________________________
"If you still don't like it, that's ok: that's why I'm boss. I
simply know better than you do."
-- Linus Torvalds
________________________________________________________________