Retaining form values in PHP

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

    Retaining form values in PHP

    Configuration:

    PHP 4.3.9
    Apache 2.0.52

    Hello PHP group,

    I am a novice to PHP. I have searched through the newsgroup on my
    issue but I am not sure I know what I am missing.

    I am creating an application to help the veterinarians at the animal
    hospital I work at.

    I have a form which present a select list of animals (from a database
    query) which belong to a client. I can see the animal names in memory
    and the client account number. When I select the appropriate animal
    from the list, I see the selected animal name ("spot") but everything
    else in memory I need (client account number) has disappeared. I've
    heard this is normal.

    I've tried storing the client account number is a session
    ($_SESSION['account_number "] before the submit, and I can see it, but
    this value too seems to be eliminated once the form is submitted.

    I've read I can use Javascript to get around this, but I want to learn
    the PHP way.

    Thanks for your time and help.

    Steve Poe

  • Benjamin Esham

    #2
    Re: Retaining form values in PHP

    Steve Poe wrote:
    I have a form which present a select list of animals (from a database
    query) which belong to a client. I can see the animal names in memory and
    the client account number. When I select the appropriate animal from the
    list, I see the selected animal name ("spot") but everything else in
    memory I need (client account number) has disappeared. I've heard this is
    normal.
    >
    I've tried storing the client account number is a session
    ($_SESSION['account_number "] before the submit, and I can see it, but this
    value too seems to be eliminated once the form is submitted.
    The "normal" way to do this, AFAIK, is to use hidden form values:

    <form ...>
    <input type="hidden" name="account_n umber" value="12345" />
    <!-- all of your normal form stuff goes here -->
    </form>

    Then your $_POST will include a value for account_number.

    HTH,
    --
    Benjamin D. Esham
    bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
    Vrei să pleci dar nu mă, nu mă iei,
    nu mă, nu mă iei, nu mă, nu mă, nu mă iei.
    Chipul tău şi dragostea din tei, / mi-amintesc de ochii tăi.

    Comment

    • Jerry Stuckle

      #3
      Re: Retaining form values in PHP

      Steve Poe wrote:
      Configuration:
      >
      PHP 4.3.9
      Apache 2.0.52
      >
      Hello PHP group,
      >
      I am a novice to PHP. I have searched through the newsgroup on my
      issue but I am not sure I know what I am missing.
      >
      I am creating an application to help the veterinarians at the animal
      hospital I work at.
      >
      I have a form which present a select list of animals (from a database
      query) which belong to a client. I can see the animal names in memory
      and the client account number. When I select the appropriate animal
      from the list, I see the selected animal name ("spot") but everything
      else in memory I need (client account number) has disappeared. I've
      heard this is normal.
      >
      I've tried storing the client account number is a session
      ($_SESSION['account_number "] before the submit, and I can see it, but
      this value too seems to be eliminated once the form is submitted.
      >
      I've read I can use Javascript to get around this, but I want to learn
      the PHP way.
      >
      Thanks for your time and help.
      >
      Steve Poe
      >
      Without seeing your code it's impossible to tell.

      However, if you're submitting a form, remember that each page has it's
      own variables. PHP doesn't remember data from one page to the next.
      The only ways to pass data from one page to the next is either with the
      $_SESSION or hidden fields in your form.

      As to the $_SESSION data disappearing - it shouldn't. Are you calling
      session_start() at the beginning of EVERY page (before ANY data is
      output) where you use session data?

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Steve Poe

        #4
        Re: Retaining form values in PHP

        Benjamin,

        Thanks for your advice. I'll look into the hidden values.

        Steve
        Benjamin Esham wrote:
        Steve Poe wrote:
        >
        I have a form which present a select list of animals (from a database
        query) which belong to a client. I can see the animal names in memory and
        the client account number. When I select the appropriate animal from the
        list, I see the selected animal name ("spot") but everything else in
        memory I need (client account number) has disappeared. I've heard this is
        normal.

        I've tried storing the client account number is a session
        ($_SESSION['account_number "] before the submit, and I can see it, but this
        value too seems to be eliminated once the form is submitted.
        >
        The "normal" way to do this, AFAIK, is to use hidden form values:
        >
        <form ...>
        <input type="hidden" name="account_n umber" value="12345" />
        <!-- all of your normal form stuff goes here -->
        </form>
        >
        Then your $_POST will include a value for account_number.
        >
        HTH,
        --
        Benjamin D. Esham
        bdesham@gmail.c om | AIM: bdesham128 | Jabber: same as e-mail
        Vrei sa pleci dar nu ma, nu ma iei,
        nu ma, nu ma iei, nu ma, nu ma, nu ma iei.
        Chipul tau si dragostea din tei, / mi-amintesc de ochii tai.

        Comment

        • Steve Poe

          #5
          Re: Retaining form values in PHP

          Jerry,

          Thanks for replying. I understand it's hard to see the problem in
          context without seeing the code. I'll try the feedback offered by most
          then post if I get stuck.
          >PHP doesn't remember data from one page to the next.
          The only ways to pass data from one page to the next is either with the
          $_SESSION or hidden fields in your form.
          I have the my inputs/forms in separate php pages. It seemed the input
          of a client account number passed back to the main php fine
          As to the $_SESSION data disappearing - it shouldn't. Are you calling
          session_start() at the beginning of EVERY page (before ANY data is
          output) where you use session data?
          No, session_start() is not on EVERY page. I have tried it on the two
          pages I have separately but not both of them together.

          Steve


          Jerry Stuckle wrote:
          Steve Poe wrote:
          Configuration:

          PHP 4.3.9
          Apache 2.0.52

          Hello PHP group,

          I am a novice to PHP. I have searched through the newsgroup on my
          issue but I am not sure I know what I am missing.

          I am creating an application to help the veterinarians at the animal
          hospital I work at.

          I have a form which present a select list of animals (from a database
          query) which belong to a client. I can see the animal names in memory
          and the client account number. When I select the appropriate animal
          from the list, I see the selected animal name ("spot") but everything
          else in memory I need (client account number) has disappeared. I've
          heard this is normal.

          I've tried storing the client account number is a session
          ($_SESSION['account_number "] before the submit, and I can see it, but
          this value too seems to be eliminated once the form is submitted.

          I've read I can use Javascript to get around this, but I want to learn
          the PHP way.

          Thanks for your time and help.

          Steve Poe
          >
          Without seeing your code it's impossible to tell.
          >
          However, if you're submitting a form, remember that each page has it's
          own variables. PHP doesn't remember data from one page to the next.
          The only ways to pass data from one page to the next is either with the
          $_SESSION or hidden fields in your form.
          >
          As to the $_SESSION data disappearing - it shouldn't. Are you calling
          session_start() at the beginning of EVERY page (before ANY data is
          output) where you use session data?
          >
          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Jerry Stuckle

            #6
            Re: Retaining form values in PHP

            Steve Poe wrote:
            Jerry,
            >
            Thanks for replying. I understand it's hard to see the problem in
            context without seeing the code. I'll try the feedback offered by most
            then post if I get stuck.
            >
            >
            >>PHP doesn't remember data from one page to the next.
            >>The only ways to pass data from one page to the next is either with the
            >>$_SESSION or hidden fields in your form.
            >
            >
            I have the my inputs/forms in separate php pages. It seemed the input
            of a client account number passed back to the main php fine
            >
            In order for it to be passed back to the main php, you must have it in
            the $_SESSION or an input field of some type (hidden or not).
            >
            >>As to the $_SESSION data disappearing - it shouldn't. Are you calling
            >>session_start () at the beginning of EVERY page (before ANY data is
            >>output) where you use session data?
            >
            >
            No, session_start() is not on EVERY page. I have tried it on the two
            pages I have separately but not both of them together.
            >
            Steve
            >
            It needs to be on EVERY PAGE which uses sessions. Otherwise the
            $_SESSION array will not be usable on that page. You can save data to
            $_SESSION, but it won't be saved in the session.

            >
            Jerry Stuckle wrote:
            >
            >>Steve Poe wrote:
            >>
            >>>Configuratio n:
            >>>
            >>>PHP 4.3.9
            >>>Apache 2.0.52
            >>>
            >>>Hello PHP group,
            >>>
            >>>I am a novice to PHP. I have searched through the newsgroup on my
            >>>issue but I am not sure I know what I am missing.
            >>>
            >>>I am creating an application to help the veterinarians at the animal
            >>>hospital I work at.
            >>>
            >>>I have a form which present a select list of animals (from a database
            >>>query) which belong to a client. I can see the animal names in memory
            >>>and the client account number. When I select the appropriate animal
            >>>from the list, I see the selected animal name ("spot") but everything
            >>>else in memory I need (client account number) has disappeared. I've
            >>>heard this is normal.
            >>>
            >>>I've tried storing the client account number is a session
            >>>($_SESSION['account_number "] before the submit, and I can see it, but
            >>>this value too seems to be eliminated once the form is submitted.
            >>>
            >>>I've read I can use Javascript to get around this, but I want to learn
            >>>the PHP way.
            >>>
            >>>Thanks for your time and help.
            >>>
            >>>Steve Poe
            >>>
            >>
            >>Without seeing your code it's impossible to tell.
            >>
            >>However, if you're submitting a form, remember that each page has it's
            >>own variables. PHP doesn't remember data from one page to the next.
            >>The only ways to pass data from one page to the next is either with the
            >>$_SESSION or hidden fields in your form.
            >>
            >>As to the $_SESSION data disappearing - it shouldn't. Are you calling
            >>session_start () at the beginning of EVERY page (before ANY data is
            >>output) where you use session data?
            >>
            >>--
            >>============= =====
            >>Remove the "x" from my email address
            >>Jerry Stuckle
            >>JDS Computer Training Corp.
            >>jstucklex@att global.net
            >>============= =====
            >
            >

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Steve Poe

              #7
              Re: Retaining form values in PHP

              I must more clueless than I thought. I added 'session_start( );' to the
              begining of each PHP I am using and I still do not see the client
              account after I submit it. I see it in the _SESSION *before* I hit
              submit.

              Steve
              It needs to be on EVERY PAGE which uses sessions. Otherwise the
              $_SESSION array will not be usable on that page. You can save data to
              $_SESSION, but it won't be saved in the session.

              Comment

              • Steve Poe

                #8
                Re: Retaining form values in PHP

                Jerry (and felllow PHP gang),

                Well, I still could not get sessions to work past a submitted form, but
                I had a breakthrough. Using the hidden input fields like:
                '<input type="hidden" name="client_ac count" value="<? echo
                str_pad($_POST["account_number "], 6, " ", STR_PAD_LEFT)?> ">' I was
                able to see the variable with the value in it.

                Until I figure out why sessions do not work, I can at least add hidden
                input fields to transfer needed values.

                Thanks.

                Steve


                Steve Poe wrote:
                I must more clueless than I thought. I added 'session_start( );' to the
                begining of each PHP I am using and I still do not see the client
                account after I submit it. I see it in the _SESSION *before* I hit
                submit.
                >
                Steve
                >
                It needs to be on EVERY PAGE which uses sessions. Otherwise the
                $_SESSION array will not be usable on that page. You can save data to
                $_SESSION, but it won't be saved in the session.

                Comment

                • Jerry Stuckle

                  #9
                  Re: Retaining form values in PHP

                  Steve Poe wrote:
                  Jerry (and felllow PHP gang),
                  >
                  Well, I still could not get sessions to work past a submitted form, but
                  I had a breakthrough. Using the hidden input fields like:
                  '<input type="hidden" name="client_ac count" value="<? echo
                  str_pad($_POST["account_number "], 6, " ", STR_PAD_LEFT)?> ">' I was
                  able to see the variable with the value in it.
                  >
                  Until I figure out why sessions do not work, I can at least add hidden
                  input fields to transfer needed values.
                  >
                  Thanks.
                  >
                  Steve
                  >
                  >
                  Steve Poe wrote:
                  >
                  >>I must more clueless than I thought. I added 'session_start( );' to the
                  >>begining of each PHP I am using and I still do not see the client
                  >>account after I submit it. I see it in the _SESSION *before* I hit
                  >>submit.
                  >>
                  >>Steve
                  >>
                  >>
                  >>>It needs to be on EVERY PAGE which uses sessions. Otherwise the
                  >>>$_SESSION array will not be usable on that page. You can save data to
                  >>>$_SESSION, but it won't be saved in the session.
                  >
                  >
                  Steve,

                  Ensure all of your errors are enabled (E_ALL) and you're displaying the
                  errors.

                  Chances are you're sending something to the client (even a single white
                  space character) before calling session-start().

                  session_start() MUST be called before ANY output is sent to the client.
                  Enabling all errors will display a warning to that effect if you are
                  doing it.

                  And your sessions won't work.

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • william.clarke

                    #10
                    Re: Retaining form values in PHP

                    Try the PHP Manual, there is a quite clear example:



                    Hope this helps.

                    William


                    Jerry Stuckle wrote:
                    Steve Poe wrote:
                    Jerry (and felllow PHP gang),

                    Well, I still could not get sessions to work past a submitted form, but
                    I had a breakthrough. Using the hidden input fields like:
                    '<input type="hidden" name="client_ac count" value="<? echo
                    str_pad($_POST["account_number "], 6, " ", STR_PAD_LEFT)?> ">' I was
                    able to see the variable with the value in it.

                    Until I figure out why sessions do not work, I can at least add hidden
                    input fields to transfer needed values.

                    Thanks.

                    Steve


                    Steve Poe wrote:
                    >I must more clueless than I thought. I added 'session_start( );' to the
                    >begining of each PHP I am using and I still do not see the client
                    >account after I submit it. I see it in the _SESSION *before* I hit
                    >submit.
                    >
                    >Steve
                    >
                    >
                    >>It needs to be on EVERY PAGE which uses sessions. Otherwise the
                    >>$_SESSION array will not be usable on that page. You can save data to
                    >>$_SESSION, but it won't be saved in the session.
                    >
                    Steve,
                    >
                    Ensure all of your errors are enabled (E_ALL) and you're displaying the
                    errors.
                    >
                    Chances are you're sending something to the client (even a single white
                    space character) before calling session-start().
                    >
                    session_start() MUST be called before ANY output is sent to the client.
                    Enabling all errors will display a warning to that effect if you are
                    doing it.
                    >
                    And your sessions won't work.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    Working...