Form fields don't persist after window.open, form submit, browser back

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jwlum@alum.mit.edu

    Form fields don't persist after window.open, form submit, browser back

    I have the following problem under Internet Explorer only:

    1. User fills out form data (myform.php) and clicks a button that fires
    myFunction()
    2. myFunction() spawns a "hello, world" popup page via window.open
    3. myFunction() submits the main page's form via document.form.s ubmit()
    5. User closes popup window and clicks browser's Back button to return
    to form entry page
    6. All the form data that the user had filled out is now blank (back to
    defaults)!

    If you take step 2) out of the equation, then the form data that the
    user submitted is still there in step 6). This is the behavior I want,
    and I am mystified as to why the addition of window.open causes a
    difference under IE. What could be going on here? If it were a
    cache-related issue, I wouldn't expect step 2) to have any bearing on
    the situation.

    Below is a single PHP file you can save to see the problem for
    yourself. As an aside, the same thing happens if you write the
    equivalent logic in perl, but in a straight HTML/javascript version,
    there is no problem.

    Thanks for any pointers,
    John

    ----------

    <html>
    <title>PHP Version</title>
    <body>
    <?php
    if ($_REQUEST['Phase'] == 'Summary')
    {
    ?>
    <p><b>Form Submitted</b></p>
    <p>This is the post-submit version of the form...</p>
    <?php
    }
    else
    {
    ?>
    <script language="javas cript">
    function submitForm()
    {
    if (document.form1 .popup[0].checked)
    {
    var popup = window.open('', 'popup', 'width=200,heig ht=200')
    popup.document. write('<html><b ody><p><b>PHP version:</b><br>Close
    me, then use browser Back button and notice that your form fields are
    empty!</p></body></html>');
    }
    document.form1. submit();
    }
    </script>
    <p>This is the pre-submit version of the form...</p>
    <form name="form1" action="" method="get">
    Text 1: <input type="text" size="12" name="text1"><b r>
    <input type="radio" name="popup" value="show"> Open Popup
    Window<br>
    <input type="radio" name="popup" value="noshow" CHECKED> No
    Popup<br>
    <input type="button" name="Submit" value="Submit"
    onclick="submit Form();">
    <input type="hidden" name="Phase" value="Summary" >
    </form>
    <?php
    }
    ?>
    </body>
    </html>

  • Scott

    #2
    Re: Form fields don't persist after window.open, form submit,browser back

    On Tue, 2006-03-21 at 11:40 -0800, jwlum@alum.mit. edu wrote:[color=blue]
    > I have the following problem under Internet Explorer only:
    >
    > 1. User fills out form data (myform.php) and clicks a button that fires
    > myFunction()
    > 2. myFunction() spawns a "hello, world" popup page via window.open
    > 3. myFunction() submits the main page's form via document.form.s ubmit()
    > 5. User closes popup window and clicks browser's Back button to return
    > to form entry page
    > 6. All the form data that the user had filled out is now blank (back to
    > defaults)!
    >
    > If you take step 2) out of the equation, then the form data that the
    > user submitted is still there in step 6). This is the behavior I want,
    > and I am mystified as to why the addition of window.open causes a
    > difference under IE. What could be going on here? If it were a
    > cache-related issue, I wouldn't expect step 2) to have any bearing on
    > the situation.
    >
    > Below is a single PHP file you can save to see the problem for
    > yourself. As an aside, the same thing happens if you write the
    > equivalent logic in perl, but in a straight HTML/javascript version,
    > there is no problem.
    >
    > Thanks for any pointers,
    > John
    >
    > ----------
    >
    > <html>
    > <title>PHP Version</title>
    > <body>
    > <?php
    > if ($_REQUEST['Phase'] == 'Summary')
    > {
    > ?>
    > <p><b>Form Submitted</b></p>
    > <p>This is the post-submit version of the form...</p>
    > <?php
    > }
    > else
    > {
    > ?>
    > <script language="javas cript">
    > function submitForm()
    > {
    > if (document.form1 .popup[0].checked)
    > {
    > var popup = window.open('', 'popup', 'width=200,heig ht=200')
    > popup.document. write('<html><b ody><p><b>PHP version:</b><br>Close
    > me, then use browser Back button and notice that your form fields are
    > empty!</p></body></html>');
    > }
    > document.form1. submit();
    > }
    > </script>
    > <p>This is the pre-submit version of the form...</p>
    > <form name="form1" action="" method="get">
    > Text 1: <input type="text" size="12" name="text1"><b r>
    > <input type="radio" name="popup" value="show"> Open Popup
    > Window<br>
    > <input type="radio" name="popup" value="noshow" CHECKED> No
    > Popup<br>
    > <input type="button" name="Submit" value="Submit"
    > onclick="submit Form();">
    > <input type="hidden" name="Phase" value="Summary" >
    > </form>
    > <?php
    > }
    > ?>
    > </body>
    > </html>
    >[/color]

    I would categorize this as a browser issue, rather than a PHP problem.
    Nonetheless, a possible workaround may be to save the submitted form
    data in session variables, and refill the form using the session data.

    You should still prevent caching of the original page for this to work,
    however. Microsoft recommends using the Expires header (header('Expire s:
    -1'); or <META HTTP-EQUIV="Expires" CONTENT="-1">).



    Comment

    • jwlum@alum.mit.edu

      #3
      Re: Form fields don't persist after window.open, form submit, browser back

      I agree that it's most generally a browser/CGI implementation issue,
      but I was hoping some fellow PHP travellers had encountered the issue
      or could shed some light on why it happens in my simple example.
      (That's assuming others can readily reproduce the behavior, which may
      not be the case if server settings are the culprit here.)

      It's true that I can get around the problem with additional code
      overhead. However, I'm hoping for pointers about why this happens at
      all, whether it's actually expected behavior, and how caching/HTTP
      header info could be coming into play here when the behavior seems to
      be controlled by DOM-related activity alone (window.open).

      Thanks for the ideas--hoping for others as well,
      John

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: Form fields don't persist after window.open, form submit, browser back

        jwlum@alum.mit. edu wrote:[color=blue]
        > I have the following problem under Internet Explorer only:
        >
        > 1. User fills out form data (myform.php) and clicks a button that fires
        > myFunction()
        > 2. myFunction() spawns a "hello, world" popup page via window.open
        > 3. myFunction() submits the main page's form via document.form.s ubmit()
        > 5. User closes popup window and clicks browser's Back button to return
        > to form entry page
        > 6. All the form data that the user had filled out is now blank (back to
        > defaults)![/color]
        <snip>

        <news:111247188 9.810924.221330 @z14g2000cwz.go oglegroups.com> (

        )

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

        Comment

        • jwlum@alum.mit.edu

          #5
          Re: Form fields don't persist after window.open, form submit, browser back

          Good info, though it doesn't seem to shed any light on why Internet
          Explorer seems to exhibit different caching behavior depending on
          whether or not a window was spawned via window.open prior to form
          submission.

          I am not using sessions at the PHP level and would rather not introduce
          that across my code base just for this, so the session-related material
          probably isn't an answer for me.

          The solution I am going to pursue is to manually write out a
          "Last-Modified" HTTP header with the last-modified time of the script
          itself. This definitely works around the apparent IE bug that I
          described above, but it may cause me other grief that I haven't
          discovered yet.

          Thanks for all the advice,
          John

          Comment

          Working...