Hi,

I used session to catch the form elements in an array, from any page. But after I started using session, whenever I try to go back to previous page by selecting 'Back' button on browser, there is no page and I get,

"Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.

To resubmit your information and view this Web page, click the Refresh button. "

message and ask to refresh the page.
If I refresh the page There are no user entered values. It's a very big page with many data entry elements.
If I remove session and use hidden input to store values, the values are retained even if I go back. If I want to keep the values when I am using session, what do I need to do?

I tried using dynamic building of text inputs by echoing the name itself.
ex:<INPUT TYPE="text" NAME="test" value="<?php echo $test;?>" >.
No use.
Any ideas? Do I need to do anything with Javascript?

Thanks
Satya

    Simple solution:
    Whenever you have multiple forms and data are passed from form to form, you can insert a "processing page" in between. This processing page captures the input from the previous page and redirect them to the next page.
    i.e. Form1 -> processing page -> Form2
    In the processing page, you will have:
    <?php
    session_start();
    foreach ($HTTP_POST_VARS as $key=>$value) {
    $session_var_name[$key] = $value;
    }
    header("location: Form2.php");
    ?>

      The processing page capturing the input from the previous page but how could I display the data in form1 when I go back?
      In form1, I tried to echo them in the input text value field,

      <INPUT TYPE="text" NAME="test" value="<?php echo "$session_var_name[test]";?>" >

      but, when I go back they are not getting displayed. But there is no warning message. I registered $session_var_name. When I tried to echo the same in processing page I was getting them.

      I tried to access that in the beginning of form1 by assigning to another variable,
      <?session_start();
      $a1 = $session_var_name[test];
      ?>
      and try to echo $a1. No use.
      By the time I am in form2 $session_var_name[test] this has value. When I go back, why can't I see that value? Once it is assigned should it be available to any page.

      Where am I doing wrong? Help!!!

      Thanks
      S

        In my processing page, I have assumed that the $session_var_name has already been registered. If you haven't registered the array, it wouldn't show up in form1.
        Try adding this after the previous code.
        <?php
        if (!session_is_registered("session_var_name")) {
        session_register("session_var_name");
        }
        ?>

          2 months later

          Hi Jonathan
          I found this example very good.
          One thing I can't understand .
          How come when I reach my final page
          I can't dump all my values.

          I made 3 pages with 4 forms objects on each
          page. in page 4 I'm trying to 'echo' all
          values .

          Thanks

          =TAnin

            Do you have "session_start()" at the beginning of each page?
            Have you also registered the session_variable at the first processing page?

              Hi ,
              I'm sorry, but it looks like my question was
              somehow not presented correctly.
              I dot these pages set so each one of them
              got back and forward custom buttons.
              Indeed when I go back with Java script "back"
              link I'm able to see the values, but each forward link is based on "submit" button, therefore once the user hit the back button and then go forward once again the values
              are missing .
              In case I'll forward the page with the browser forward icon the values are kept.
              I can't figure it out how to resolve this
              scenario.

              What am I doing wrong ?

              Thanks

              =TAnin

                Sample quick fix:

                form 1:
                session_start();
                if (!session_is_register("sess_array") {
                session_register("sess_array");
                }
                <form action="processForm1.php" method="post">
                <input name="var1">
                <input name="var2">
                </form>

                processForm1:
                session_start();
                foreach ($HTTP_POST_VARS as $key=>$value) {
                $sess_array[$key] = $value;
                }
                header("location: form2.php");
                exit;

                form2.php
                session_start();
                <tr>
                <td>Value from previous page<td>
                <td><?=$sess_array[var1]?></td>
                </tr>
                <tr>
                <td>Value from previous page<td>
                <td><?=$sess_array[var2?></td>
                </tr>

                I hope it helps.

                  TAnin,

                  With your code you can see values when you go back not when forward. Jonathan code works good , you can see values when forward but the problem with processing forms you can't see values when you go back again, if you want, even if they are available in session variables. So, in the previous page (form1), you need to put the values in INPUT fields.
                  ex:

                  <input name="var1"
                  value="<? echo "$sess_array[var1]";?>">

                  <input name="var2"
                  value="<? echo "$sess_array[var2]";?>">

                  Hope this avoids the further trouble.

                  -Satya

                    Thanks Satya for pointing out my mistake =)

                      Hi, thanks for your input.
                      For the textfield objects it's working well for me but how do I handle /implement this over radio buttons ?

                      <input type="text" name="f1"value="<? echo "$session_var_name[f1]";?>">

                      <input type="radio" name="f2" value="1">
                      <input type="radio" name="f2" value="2">
                      <input type="radio" name="f2" value="3">

                      All using the same name .
                      I know this maybe off topic,
                      I'll appreciate any help

                      Thanks

                      =TAnin

                        You could try something like this:
                        <input type="radio" name="f2" value="1" <? if ($session_var_name[f1]=="1") print "checked";?> >

                          7 days later

                          Thanks for this one - it's working well :-)

                          =TAnin

                            7 days later

                            Say, what magic would I need in order to do
                            the same thing with a combo box e.g. select ( option value= ) ?

                            Thanks in advance .

                            =TAnin

                              similar to my previous example:
                              <select name="theName">
                              <option value="value1" <?php if ($session_array["theName"]=="value1") print " selected"; ?> >
                              <option value="value2" <?php if ($session_array["theName"]=="value2") print " selected"; ?> >
                              ... etc.

                                2 months later

                                Hi Folks,

                                I tried the codes to send information from one page to another with the session start and session registetr. They all worked!!

                                You can find those codes in the URL below:

                                http://www.phpbuilder.com/forum/read.php3?num=2&id=125538&loc=0&thread=125538

                                With Netscape, they work fine. Unfortunately, there's a problem with Internet Explorer. If i hit the go back button, all the information are gone. Then, I put the echo for the values on all the forms so the values stay. Now, the other problem come. I can't reset the forms if I put echo for the values.
                                Here is the sample of my code:
                                <input type=text name=var1 value="<? echo $sess_array[var1]; ?>
                                Can anyone help me?
                                Thanks in advance.

                                Mike

                                  3 months later

                                  there is a much simpler solution just call the header function like this:

                                  header("Cache-Control: Public");

                                    a month later

                                    Ok, this did the job then.
                                    I'm facing today a dynamice data from MySQL

                                    Here is the code I'm using to create the list box :


                                    <SELECT class=textbox NAME=requiredQuestion_A>
                                    <?
                                    $mnglist = mysql_query("select ename, title, code from emanagers01 order by ename");
                                    echo "<OPTION VALUE=\"\">".(" Choose Manager ")."</option>\n";
                                    while(list($title, $ename, $code) = mysql_fetch_row($mnglist)) {
                                    if ($ename==$manager) { $sel = "selected "; }
                                    echo "<option $sel value=\"$code\">$title - $ename</option>\n";
                                    $sel = "";
                                    }

                                    ?>

                                    </select>

                                    --

                                    How can I use the session, to print the selected value ?

                                    Thanks

                                      a month later
                                      23 days later

                                      Where does this code need to be placed - every page, or just on the pages that can expire?

                                      BTW, what are the rules concerning page expirations?

                                        Write a Reply...