SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    at home
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool PHP and previous form contents

    Hi,

    I have an application that lets a user enter form information. They can fill out multiple copies of the same form. I would like them to be able to go back and make corrections to the previous forms they filled out (all in the current session).

    What is a good approach for doing this?

    TIA

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll need to store the data. You could use $_SESSION for this. Actually it's not a trivial task, since the way you solve it has a big impact on how your application is structured. You might want to have a look at the infamous Application Controller thread for some discussion on how to solve the issue, or you could take a plunge into some of the existing frameworks available, which all solves the issue and some more. PEAR::HTML_QuickForm may be a good start.

  3. #3
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perhaps I've misunderstood, but this looks like the issue Benjymouse pointed out in this thread: Maintaining separate user interface states in simultaneous windows or tabs.

    Quote Originally Posted by Benjymouse
    In short the rule goes: Each individual window/tab must still perform the same way, regardless of what happens in the other windows/tabs. Of course, I would expect the the windows/tabs to be data integrated (showing changes committed by other instances), but they may not interfere with eachother apart from this. Specifically navigation should be regarded as local (and thus isolated) to the window/tab.

    IMO this pretty much rules out storage of "selected menu option" in session or in a cookie.

    If you can deduce the selected menu option from the searchstring or url, that's the way to go. Sub-page navigation must then guarantee to retain that part of the searchstring on subsequent requests. This will also guarantee that the correct menu option will be highlighted even if the user followed a link from another page site or even bookmark.
    A more general solution might be to store the actual data on the state of the user interface in $_SESSION and keep an ID for the state in the URL. I've never tried it, so I've no idea what complications might occur, but something like this:

    PHP Code:
    // URL: index.php?a=1&b=2&state=4

    $state $_SESSION['state'][$request->state]
    $values $state->getFormContents(); // Form contents is just an example of what might be in there 
    For each operation that changes the state of the user interface, generate a new state ID and store the state in $_SESSION with the state ID as a key. Add the new state ID to all URLs and forms.
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    at home
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ic. hmm, if the user has entered, say 5 forms of data while using the website, I want them to be able to step back through them in case they need to edit them.

  5. #5
    SitePoint Guru dagfinn's Avatar
    Join Date
    Jan 2004
    Location
    Oslo, Norway
    Posts
    894
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arbora2
    ic. hmm, if the user has entered, say 5 forms of data while using the website, I want them to be able to step back through them in case they need to edit them.
    So you just want to keep the history of the different forms. That's something else than what I was talking about.

    I was playing with my new hammer, and everything looked like a nail.

    But the issue exists in principle, although it may not be likely to happen with forms.
    Dagfinn Reiersøl
    PHP in Action / Blog / Twitter
    "Making the impossible possible, the possible easy,
    and the easy elegant"
    -- Moshe Feldenkrais

  6. #6
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well - perhaps you would want to store the data to a persistent medium, such as a database ?


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
  •