The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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).

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.

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.

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.