function for capturing form input won't return anything

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    function for capturing form input won't return anything

    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="pa ssword") {
    // 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_VA RS[$var]) {
    $value = $this->HTTP_POST_VA RS[$var];
    echo "here is the value of post vars: $value";
    } elseif ($this->HTTP_GET_VAR S[$var]) {
    $value = $this->HTTP_GET_VAR S[$var];
    echo $value;
    } elseif ($this->HTTP_ENV_VAR S[$var]) {
    $value = $this->HTTP_ENV_VAR S[$var];
    echo $value;
    } elseif ($this->HTTP_SERVER_VA RS[$var]) {
    $value = $this->HTTP_SERVER_VA RS[$var];
    echo $value;
    } elseif ($this->HTTP_COOKIE_VA RS[$var]) {
    $value = $this->HTTP_COOKIE_VA RS[$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_VA RS = $GLOBALS["HTTP_SERVER_VA RS"];
    $this->HTTP_POST_VA RS = $GLOBALS["HTTP_POST_VARS "];
    $this->HTTP_GET_VAR S = $GLOBALS["HTTP_GET_V ARS"];
    $this->HTTP_COOKIE_VA RS = $GLOBALS["HTTP_COOKIE_VA RS"];
    $this->HTTP_ENV_VAR S = $GLOBALS["HTTP_ENV_V ARS"];

    $this->id = 1;
    }
  • sam

    #2
    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_VA RS[$var]))
    {

    }
    elseif(isset($t his->HTTP_GET_VAR S[$var]))
    {

    }
    .........

    Hope this helps


    lkrubner@geocit ies.com (lawrence) wrote in message news:<da7e68e8. 0307051057.6060 f1fa@posting.go ogle.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="pa ssword") {
    > // 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_VA RS[$var]) {
    > $value = $this->HTTP_POST_VA RS[$var];
    > echo "here is the value of post vars: $value";
    > } elseif ($this->HTTP_GET_VAR S[$var]) {
    > $value = $this->HTTP_GET_VAR S[$var];
    > echo $value;
    > } elseif ($this->HTTP_ENV_VAR S[$var]) {
    > $value = $this->HTTP_ENV_VAR S[$var];
    > echo $value;
    > } elseif ($this->HTTP_SERVER_VA RS[$var]) {
    > $value = $this->HTTP_SERVER_VA RS[$var];
    > echo $value;
    > } elseif ($this->HTTP_COOKIE_VA RS[$var]) {
    > $value = $this->HTTP_COOKIE_VA RS[$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_VA RS = $GLOBALS["HTTP_SERVER_VA RS"];
    > $this->HTTP_POST_VA RS = $GLOBALS["HTTP_POST_VARS "];
    > $this->HTTP_GET_VAR S = $GLOBALS["HTTP_GET_V ARS"];
    > $this->HTTP_COOKIE_VA RS = $GLOBALS["HTTP_COOKIE_VA RS"];
    > $this->HTTP_ENV_VAR S = $GLOBALS["HTTP_ENV_V ARS"];
    >
    > $this->id = 1;
    > }[/color]

    Comment

    • lawrence

      #3
      Re: function for capturing form input won't return anything

      rbaba99@caramai l.com (sam) wrote in message news:<fd2aa5c7. 0307071335.7149 f2dc@posting.go ogle.com>...[color=blue]
      > Use the function isset to test if a variable is set :
      >
      > if(isset($this->HTTP_POST_VA RS[$var]))
      > {
      >
      > }
      > elseif(isset($t his->HTTP_GET_VAR S[$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@geocit ies.com (lawrence) wrote in message news:<da7e68e8. 0307051057.6060 f1fa@posting.go ogle.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="pa ssword") {
      > > // 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_VA RS[$var]) {
      > > $value = $this->HTTP_POST_VA RS[$var];
      > > echo "here is the value of post vars: $value";
      > > } elseif ($this->HTTP_GET_VAR S[$var]) {
      > > $value = $this->HTTP_GET_VAR S[$var];
      > > echo $value;
      > > } elseif ($this->HTTP_ENV_VAR S[$var]) {
      > > $value = $this->HTTP_ENV_VAR S[$var];
      > > echo $value;
      > > } elseif ($this->HTTP_SERVER_VA RS[$var]) {
      > > $value = $this->HTTP_SERVER_VA RS[$var];
      > > echo $value;
      > > } elseif ($this->HTTP_COOKIE_VA RS[$var]) {
      > > $value = $this->HTTP_COOKIE_VA RS[$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_VA RS = $GLOBALS["HTTP_SERVER_VA RS"];
      > > $this->HTTP_POST_VA RS = $GLOBALS["HTTP_POST_VARS "];
      > > $this->HTTP_GET_VAR S = $GLOBALS["HTTP_GET_V ARS"];
      > > $this->HTTP_COOKIE_VA RS = $GLOBALS["HTTP_COOKIE_VA RS"];
      > > $this->HTTP_ENV_VAR S = $GLOBALS["HTTP_ENV_V ARS"];
      > >
      > > $this->id = 1;
      > > }[/color][/color]

      Comment

      • Jochen Daum

        #4
        Re: function for capturing form input won't return anything

        Hi lawrence!

        On 10 Jul 2003 11:11:11 -0700, lkrubner@geocit ies.com (lawrence)
        wrote:
        [color=blue]
        >rbaba99@carama il.com (sam) wrote in message news:<fd2aa5c7. 0307071335.7149 f2dc@posting.go ogle.com>...[color=green]
        >> Use the function isset to test if a variable is set :
        >>
        >> if(isset($this->HTTP_POST_VA RS[$var]))
        >> {
        >>
        >> }
        >> elseif(isset($t his->HTTP_GET_VAR S[$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.
        Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

        Comment

        • Gary Petersen

          #5
          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?

          Comment

          • Gary Petersen

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

            Comment

            Working...