Connecting Tech Pros Worldwide Forums | Help | Site Map

function for capturing form input won't return anything

lawrence
Guest
 
Posts: n/a
#1: Jul 16 '05
I've this function, which is the method of a class. I'm posting the
constructor of the class down below. For some reason, when I fill out
a form and hit submit, I'm not getting any values. Can someone tell me
why?




function getVar($var="password") {
// 05-08-03 - the important thing about this function is it reverses
PHP's built-in load
// order for variables. PHP usually loads COOKIE last, so if you've
a competing POST and
// COOKIE, the POST loses. This is nuts, in my opinion, if someone
just posted a form, you
// almost always want that to have top priority. And that is what
this function does.

// 05-27-03 - I just discovered user created globals go in a var
called $GLOBALS which has been around
// since PHP 3.0. Even though it is old, I'm putting it at the end,
partly for security, but also
// because it is auto-global and therefore belongs with the other
auto-globals.

if ($this->HTTP_POST_VARS[$var]) {
$value = $this->HTTP_POST_VARS[$var];
echo "here is the value of post vars: $value";
} elseif ($this->HTTP_GET_VARS[$var]) {
$value = $this->HTTP_GET_VARS[$var];
echo $value;
} elseif ($this->HTTP_ENV_VARS[$var]) {
$value = $this->HTTP_ENV_VARS[$var];
echo $value;
} elseif ($this->HTTP_SERVER_VARS[$var]) {
$value = $this->HTTP_SERVER_VARS[$var];
echo $value;
} elseif ($this->HTTP_COOKIE_VARS[$var]) {
$value = $this->HTTP_COOKIE_VARS[$var];
echo $value;
} elseif ($_POST[$var]) {
$value = $_POST[$var];
echo $value;
} elseif ($_GET[$var]) {
$value = $_GET[$var];
echo $value;
} elseif ($_ENV[$var]) {
$value = $ENV[$var];
echo $value;
} elseif ($_SERVER[$var]) {
$value = $_SERVER[$var];
echo $value;
} elseif ($_COOKIE[$var]) {
$value = $_COOKIE[$var];
echo $value;
} elseif ($GLOBALS[$var]) {
$value = $GLOBALS[$var];
echo $value;
}
return $value;
}














function McInputOutput() {
// 06-20-03 - the global keyword doesn't work inside of objects, and
so we must use this
// method to get these old variables. You might ask, "Why not just
go with the new Super
// Globals, like $_GET?" The answer is that I've installed this cms
on a suprising number of
// hosts running old versions of PHP that don't support the new auto
globals. So it is good
// to be backwards compatible.
$this->HTTP_SERVER_VARS = $GLOBALS["HTTP_SERVER_VARS"];
$this->HTTP_POST_VARS = $GLOBALS["HTTP_POST_VARS"];
$this->HTTP_GET_VARS = $GLOBALS["HTTP_GET_VARS"];
$this->HTTP_COOKIE_VARS = $GLOBALS["HTTP_COOKIE_VARS"];
$this->HTTP_ENV_VARS = $GLOBALS["HTTP_ENV_VARS"];

$this->id = 1;
}

sam
Guest
 
Posts: n/a
#2: Jul 16 '05

re: function for capturing form input won't return anything


Use the function isset to test if a variable is set :

if(isset($this->HTTP_POST_VARS[$var]))
{

}
elseif(isset($this->HTTP_GET_VARS[$var]))
{

}
.........

Hope this helps


lkrubner@geocities.com (lawrence) wrote in message news:<da7e68e8.0307051057.6060f1fa@posting.google. com>...[color=blue]
> I've this function, which is the method of a class. I'm posting the
> constructor of the class down below. For some reason, when I fill out
> a form and hit submit, I'm not getting any values. Can someone tell me
> why?
>
>
>
>
> function getVar($var="password") {
> // 05-08-03 - the important thing about this function is it reverses
> PHP's built-in load
> // order for variables. PHP usually loads COOKIE last, so if you've
> a competing POST and
> // COOKIE, the POST loses. This is nuts, in my opinion, if someone
> just posted a form, you
> // almost always want that to have top priority. And that is what
> this function does.
>
> // 05-27-03 - I just discovered user created globals go in a var
> called $GLOBALS which has been around
> // since PHP 3.0. Even though it is old, I'm putting it at the end,
> partly for security, but also
> // because it is auto-global and therefore belongs with the other
> auto-globals.
>
> if ($this->HTTP_POST_VARS[$var]) {
> $value = $this->HTTP_POST_VARS[$var];
> echo "here is the value of post vars: $value";
> } elseif ($this->HTTP_GET_VARS[$var]) {
> $value = $this->HTTP_GET_VARS[$var];
> echo $value;
> } elseif ($this->HTTP_ENV_VARS[$var]) {
> $value = $this->HTTP_ENV_VARS[$var];
> echo $value;
> } elseif ($this->HTTP_SERVER_VARS[$var]) {
> $value = $this->HTTP_SERVER_VARS[$var];
> echo $value;
> } elseif ($this->HTTP_COOKIE_VARS[$var]) {
> $value = $this->HTTP_COOKIE_VARS[$var];
> echo $value;
> } elseif ($_POST[$var]) {
> $value = $_POST[$var];
> echo $value;
> } elseif ($_GET[$var]) {
> $value = $_GET[$var];
> echo $value;
> } elseif ($_ENV[$var]) {
> $value = $ENV[$var];
> echo $value;
> } elseif ($_SERVER[$var]) {
> $value = $_SERVER[$var];
> echo $value;
> } elseif ($_COOKIE[$var]) {
> $value = $_COOKIE[$var];
> echo $value;
> } elseif ($GLOBALS[$var]) {
> $value = $GLOBALS[$var];
> echo $value;
> }
> return $value;
> }
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> function McInputOutput() {
> // 06-20-03 - the global keyword doesn't work inside of objects, and
> so we must use this
> // method to get these old variables. You might ask, "Why not just
> go with the new Super
> // Globals, like $_GET?" The answer is that I've installed this cms
> on a suprising number of
> // hosts running old versions of PHP that don't support the new auto
> globals. So it is good
> // to be backwards compatible.
> $this->HTTP_SERVER_VARS = $GLOBALS["HTTP_SERVER_VARS"];
> $this->HTTP_POST_VARS = $GLOBALS["HTTP_POST_VARS"];
> $this->HTTP_GET_VARS = $GLOBALS["HTTP_GET_VARS"];
> $this->HTTP_COOKIE_VARS = $GLOBALS["HTTP_COOKIE_VARS"];
> $this->HTTP_ENV_VARS = $GLOBALS["HTTP_ENV_VARS"];
>
> $this->id = 1;
> }[/color]
lawrence
Guest
 
Posts: n/a
#3: Jul 16 '05

re: function for capturing form input won't return anything


rbaba99@caramail.com (sam) wrote in message news:<fd2aa5c7.0307071335.7149f2dc@posting.google. com>...[color=blue]
> Use the function isset to test if a variable is set :
>
> if(isset($this->HTTP_POST_VARS[$var]))
> {
>
> }
> elseif(isset($this->HTTP_GET_VARS[$var]))
> {
>
> }[/color]


I don't understand how this could much improve things, though I do
understand that in some technical sense it is better syntax for the
test I want to do. Perhaps I'll try it when I've spare time today.

However, you miss the main thing I'm curious about: as a function in
procedural code, this function works well and has never failed me. Now
that I'm trying to make it the method of an object, it has stopped
working. I'm looking for something that is specific to the object that
would cause it not to work. I've already checked what I thought was
obvious: do the variables have scope here, am I using the "$this->"
syntax. It seems I've done all that, yet the code won't work, and, as
I say, it works well as a function outside of this class.

For now, I've gone back to using getVar, the function, rather than
$io->getVar, the class method. But as I'm moving to OO, I'd like to
figure out how to make this function work as a class method.









[color=blue]
> ........
>
> Hope this helps
>
>
> lkrubner@geocities.com (lawrence) wrote in message news:<da7e68e8.0307051057.6060f1fa@posting.google. com>...[color=green]
> > I've this function, which is the method of a class. I'm posting the
> > constructor of the class down below. For some reason, when I fill out
> > a form and hit submit, I'm not getting any values. Can someone tell me
> > why?
> >
> >
> >
> >
> > function getVar($var="password") {
> > // 05-08-03 - the important thing about this function is it reverses
> > PHP's built-in load
> > // order for variables. PHP usually loads COOKIE last, so if you've
> > a competing POST and
> > // COOKIE, the POST loses. This is nuts, in my opinion, if someone
> > just posted a form, you
> > // almost always want that to have top priority. And that is what
> > this function does.
> >
> > // 05-27-03 - I just discovered user created globals go in a var
> > called $GLOBALS which has been around
> > // since PHP 3.0. Even though it is old, I'm putting it at the end,
> > partly for security, but also
> > // because it is auto-global and therefore belongs with the other
> > auto-globals.
> >
> > if ($this->HTTP_POST_VARS[$var]) {
> > $value = $this->HTTP_POST_VARS[$var];
> > echo "here is the value of post vars: $value";
> > } elseif ($this->HTTP_GET_VARS[$var]) {
> > $value = $this->HTTP_GET_VARS[$var];
> > echo $value;
> > } elseif ($this->HTTP_ENV_VARS[$var]) {
> > $value = $this->HTTP_ENV_VARS[$var];
> > echo $value;
> > } elseif ($this->HTTP_SERVER_VARS[$var]) {
> > $value = $this->HTTP_SERVER_VARS[$var];
> > echo $value;
> > } elseif ($this->HTTP_COOKIE_VARS[$var]) {
> > $value = $this->HTTP_COOKIE_VARS[$var];
> > echo $value;
> > } elseif ($_POST[$var]) {
> > $value = $_POST[$var];
> > echo $value;
> > } elseif ($_GET[$var]) {
> > $value = $_GET[$var];
> > echo $value;
> > } elseif ($_ENV[$var]) {
> > $value = $ENV[$var];
> > echo $value;
> > } elseif ($_SERVER[$var]) {
> > $value = $_SERVER[$var];
> > echo $value;
> > } elseif ($_COOKIE[$var]) {
> > $value = $_COOKIE[$var];
> > echo $value;
> > } elseif ($GLOBALS[$var]) {
> > $value = $GLOBALS[$var];
> > echo $value;
> > }[/color]
> return $value;[color=green]
> > }
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > function McInputOutput() {
> > // 06-20-03 - the global keyword doesn't work inside of objects, and
> > so we must use this
> > // method to get these old variables. You might ask, "Why not just
> > go with the new Super
> > // Globals, like $_GET?" The answer is that I've installed this cms
> > on a suprising number of
> > // hosts running old versions of PHP that don't support the new auto
> > globals. So it is good
> > // to be backwards compatible.
> > $this->HTTP_SERVER_VARS = $GLOBALS["HTTP_SERVER_VARS"];
> > $this->HTTP_POST_VARS = $GLOBALS["HTTP_POST_VARS"];
> > $this->HTTP_GET_VARS = $GLOBALS["HTTP_GET_VARS"];
> > $this->HTTP_COOKIE_VARS = $GLOBALS["HTTP_COOKIE_VARS"];
> > $this->HTTP_ENV_VARS = $GLOBALS["HTTP_ENV_VARS"];
> >
> > $this->id = 1;
> > }[/color][/color]
Jochen Daum
Guest
 
Posts: n/a
#4: Jul 16 '05

re: function for capturing form input won't return anything


Hi lawrence!

On 10 Jul 2003 11:11:11 -0700, lkrubner@geocities.com (lawrence)
wrote:
[color=blue]
>rbaba99@caramail.com (sam) wrote in message news:<fd2aa5c7.0307071335.7149f2dc@posting.google. com>...[color=green]
>> Use the function isset to test if a variable is set :
>>
>> if(isset($this->HTTP_POST_VARS[$var]))
>> {
>>
>> }
>> elseif(isset($this->HTTP_GET_VARS[$var]))
>> {
>>
>> }[/color]
>
>
>I don't understand how this could much improve things, though I do
>understand that in some technical sense it is better syntax for the
>test I want to do. Perhaps I'll try it when I've spare time today.
>[/color]
You always have to check, if a variable has a value at all and then,
if the value is within range of the values you expect.
[color=blue]
>However, you miss the main thing I'm curious about: as a function in
>procedural code, this function works well and has never failed me. Now
>that I'm trying to make it the method of an object, it has stopped
>working. I'm looking for something that is specific to the object that
>would cause it not to work. I've already checked what I thought was
>obvious: do the variables have scope here, am I using the "$this->"
>syntax. It seems I've done all that, yet the code won't work, and, as
>I say, it works well as a function outside of this class.[/color]

I only see you using $HTTP_POST_VARS witthout global. You can only do
that with $_POST, which is superglobal. MAybe thats the problem.

[color=blue]
>
>For now, I've gone back to using getVar, the function, rather than
>$io->getVar, the class method. But as I'm moving to OO, I'd like to
>figure out how to make this function work as a class method.
>[/color]


HTH, Jochen
--
Jochen Daum - CANS Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Gary Petersen
Guest
 
Posts: n/a
#5: Jul 16 '05

re: function for capturing form input won't return anything


On Sun, 13 Jul 2003 15:24:36 -0500, Jochen Daum wrote:
[color=blue]
>
> I only see you using $HTTP_POST_VARS witthout global. You can only do
> that with $_POST, which is superglobal. MAybe thats the problem.
>[/color]

What is a superglobal?

Gary Petersen
Guest
 
Posts: n/a
#6: Jul 16 '05

re: function for capturing form input won't return anything


On Tue, 15 Jul 2003 00:02:04 -0500, Jochen Daum wrote:
[color=blue][color=green]
>>What is a superglobal?[/color]
>
> A variable which is available in all functions and outside as well.
> Check out www.php.net
>
> HTH, Jochen[/color]

Thanks Jochen

Closed Thread