Results 1 to 8 of 8

Thread: Form data & Back button

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Wink Form data & Back button

    I have a form and here's what I have an issue with....

    If the user types something in the boxes, and then accidentally goes to another site/page in the site WITHOUT hitting submit on the form, all the data is lost when they click the back browser button. What I want them to be able to do is hit the back button and all the information to still be there.

    How can I do this? I'm using php, so I don't know if I've posted this in the right forum.... I've seen this on many other sites just don't know how to do it.

    Any help would be appreciated!

  2. #2
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    A quick example of this at work would be yahoo email. If you compose an email and type a subject, to, and main email and then go to another site. You hit back and the info you entered is still all there (even though the email was never sent)

  3. #3
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could use Javascript Cookies to accomplish this. Not sure how exactly, but I do know it can be done.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  4. #4
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Is there a way to do this without using cookies? If not, does anybody know how to accomplish this with Javascript cookies? I'm not familiar with javascript cookies....

    Thanks!

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Yes, there is. Use a browser that works like this. Some browsers, and even sometimes some forms in some browsers remember, while others do not.

    Short of using cookies, no, there is not another way to override the default. (I suppose you could try to use ajax and a database, but that is way too much work. Cookies are a much better.)

    Not sure how to use them with javascript myself, but you could use the onChange value for all fields in the form, then store the value into the cookie of the same name as the name/id of that field in the form.

    For the javascript, take a look here--
    http://www.quirksmode.org/js/cookies.html
    Or, of course--
    http://www.google.com/search?q=javascript+set+cookie
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As djr33 pointed out, it is an built-in function of some browsers to retain the values from form fields when revisiting them via the Back and Forward buttons.

    This functionality cannot be replicated reliably: using the Back and Forward buttons neither generates new requests to the server, nor does it necessarily cause scripts to be re-executed (in Firefox, for instance).
    Mike

  7. #7
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help you guys.... here's what I'm doing and every time i type something in this title box part of the form and then go to another site and hit the back browser button, nothing is in the title box....This is the case with Firefox and IE

    I think this is right from everything I've read...

    PHP Code:
    <input name="txt_blogname" type="text" id="txt_blogname" value="<?php  echo $_COOKIE["TestCookie"]; ?>" size="75" maxlength="100">
                                <?php
    $value
    =$HTTP_POST_VARS['txt_blogname'];

    // send a simple cookie
    setcookie("TestCookie",$value);
    ?>
    I've tried putting the setcookie part before the textbox and after it and neither works... Any help would be appreciated.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP is only parsed upon a new request. Back and forward are from your cache, so that's just as good as a pure html page, without anything dynamic about it.

    Using javascript is the only option. (Though I like PHP more in general myself.)

    I think the one loophole to what John said, though he made some great points, is that you could have it check for content always and somehow know that the page was revisited. It would be complex and resource intensive, but it would be possible. But... not worth it unless you REALLY need this.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •