Trouble With Sessions

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

    #1

    Trouble With Sessions

    I have a form that will be preserving form data prior to processing
    the form data. Upon clicking a certain submit button you will go to
    another PHP script that will contain the following code:

    if (strcmp(strtolo wer($_POST['submit']), 'apply') != 0) { // GO BACK
    TO grad_applicatio n with $_SESSION
    session_start() ;
    if (sizeof($_POST) > 0) $_SESSION['post'] = $_POST;
    if (sizeof($_GET) > 0) $_SESSION['get'] = $_GET;
    header("Locatio n: http://$SERVER_NAME${d evpath}grad_app lication.php?"
    .. Session_Name() . '=' . Session_Id());
    }

    Upon redirection back to the original PHP form script I will include
    an "HTML" file (its extension is HTML but it's actually PHP) that
    should prepopulate the form fields with the data from $_SESSION. At
    the top of my page I have:

    session_start() ;

    However, while I see the PHPSESSID in my query string I do not see any
    of my form elements populated. This is how I am parsing $_SESSION in
    the "HTML" file:

    /*----------------------------------------------------------------------------------------------
    Unclear as to how $_POST and $_GET vars are set, so as a backup, save
    them here in macros.inc
    ------------------------------------------------------------------------------------------------*/
    foreach ($_POST as $key => $val) {
    if (!isset(${$key} )) ${$key} = $val;
    }

    foreach ($_GET as $key => $val) {
    if (!isset(${$key} )) ${$key} = $val;
    }

    if (preg_match('/grad_applicatio n\.php/i', $REQUEST_URI) &&
    isset($_SESSION['post'])) {
    foreach ($_SESSION['post'] as $key => $val) {
    $blah .= "key = $key and val = $val<P>\n";
    if (!isset(${$key} )) ${$key} = $val;
    }
    }

    if (preg_match('/grad_applicatio n\.php/i', $REQUEST_URI) &&
    isset($_SESSION['get'])) {
    foreach ($_SESSION['get'] as $key => $val) {
    if (!isset(${$key} )) ${$key} = $val;
    }
    }

    //---END OF FORM VAR DYNAMIC SETTING
    BLOCK------------------------------------------------------

    This was all based on php.net information on sessions at:


    and at


    I've never had any success with sessions to be honest. Maybe I'm
    approaching this whole thing wrong. Bottom line is that I want to
    produce a form that has a button that will produce more form elements
    upon click while retaining everything you typed so far.

    Phil
  • Paulus Magnus

    #2
    Re: Trouble With Sessions

    "Phil Powell" <soazine@erols. com> wrote in message
    news:1cdca2a7.0 310071120.2ecb0 4b8@posting.goo gle.com...[color=blue]
    > I have a form that will be preserving form data prior to processing
    > the form data. Upon clicking a certain submit button you will go to
    > another PHP script that will contain the following code:
    >
    > 8< SNIP! >8
    >
    > I've never had any success with sessions to be honest. Maybe I'm
    > approaching this whole thing wrong. Bottom line is that I want to
    > produce a form that has a button that will produce more form elements
    > upon click while retaining everything you typed so far.[/color]

    Phew!!! Glad you got to the original problem or I was going to pass on this
    one.

    Are the form elements similar because maybe you should use an array of
    elements; i.e.

    <input name="name[0]" type="text" value="<?=$_POS T['name'][0]?>">
    <input name="name[1]" type="text" value="<?=$_POS T['name'][1]?>">

    And then when they want more you can just add some more and because you're
    setting the initial values of these input fields to the same as what's
    contained in the $_POST array you don't have to worry about storing the
    values outside the web page.

    Sessions do work very well but they're not always the easiest solution to
    problems.

    Paulus


    Comment

    • Phil Powell

      #3
      Re: Trouble With Sessions

      Thanx but that would've failed. upon clicking the button you are
      redirected from grad_applicatio n.php to grad_applicatio n_redirect.php
      only to return BACK to grad_applicatio n.php with retained vars or
      doing processing depending on which submit button you clicked.

      I got it solved, I had to move $_SESSION to the function inside a
      class object instance in a library elsewhere.

      Phil

      "Paulus Magnus" <paulus.magnus@ loves-spam.com> wrote in message news:<blvefr$ke l$1@titan.btint ernet.com>...[color=blue]
      > "Phil Powell" <soazine@erols. com> wrote in message
      > news:1cdca2a7.0 310071120.2ecb0 4b8@posting.goo gle.com...[color=green]
      > > I have a form that will be preserving form data prior to processing
      > > the form data. Upon clicking a certain submit button you will go to
      > > another PHP script that will contain the following code:
      > >
      > > 8< SNIP! >8
      > >
      > > I've never had any success with sessions to be honest. Maybe I'm
      > > approaching this whole thing wrong. Bottom line is that I want to
      > > produce a form that has a button that will produce more form elements
      > > upon click while retaining everything you typed so far.[/color]
      >
      > Phew!!! Glad you got to the original problem or I was going to pass on this
      > one.
      >
      > Are the form elements similar because maybe you should use an array of
      > elements; i.e.
      >
      > <input name="name[0]" type="text" value="<?=$_POS T['name'][0]?>">
      > <input name="name[1]" type="text" value="<?=$_POS T['name'][1]?>">
      >
      > And then when they want more you can just add some more and because you're
      > setting the initial values of these input fields to the same as what's
      > contained in the $_POST array you don't have to worry about storing the
      > values outside the web page.
      >
      > Sessions do work very well but they're not always the easiest solution to
      > problems.
      >
      > Paulus[/color]

      Comment

      Working...