+2  A: 

It sounds like type of user messaging system is needed. By this what I mean the process could look similar to the following:

  1. The user submits the form
  2. The system could register the user for a set of notifications/messages (store in a DB table or something along those lines.
  3. The system send the redirect response to the user
  4. On the next page load for the user the system would check to see if the user had any pending messages.
  5. If they do then remove them from the pending list/table and add them to the page

This keeps you from having a page state issue while still providing the user with the messages to be displayed, note that you might need to tweak the specifics to your needs.

Hope this helps.

confusedGeek
Hi confusedGeek, thank you for the suggestion. This is actually an option I was considering myself, but using DB for storage seemed like an overkill in order to just address confirmation message handling. From a processing point, using $_SESSION would be more effective as in this case it's only a temporary storage - both alternatives however have to handle extra checks to prevent mixing of messages between individual page loads (i.e. users switching context / working in multiple tabs).
MicE
+1  A: 

ASP.NET

Since the question is presented as language agnostic, you might be interested in ASP.NET's Server.Transfer which does exactly what you want to achieve.


PHP

However for PHP, the situation doesn't seem to be very easy and all solutions that come into my mind have design smells:

Sessions

Using sessions to mark your data with certain flags and then check and use them on overview page. You just have to be sure you always unset these data after you don't need them anymore, which might be tricky.

Database

Queue those data in database as confusedGeek described in his post, but I don't think it's a good idea to query every single request like this. It's going to be quite many requests on DB server if you application is bit bigger, which might slow things down.

cURL

Taking advantage of cURL in PHP, if you have the chance:

<?php
$curl = curl_init( );

curl_setopt( $curl, CURLOPT_URL, "http://localhost/something.php" );
curl_setopt( $curl, CURLOPT_POST, true );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $_POST );

curl_exec( $curl );
curl_close( $curl );
?>

<form action="test.php" method="post">
    <input id="textfield" name="textfield" />
    <input type="submit" />
</form>

This piece of code takes something.php on server side, allows to send POST data to it and shows you its content (which could be just print_r( $POST ); in this example). This one could do what you need, but it has once again one flaw - the URL won't change, so users might get confused - and I wouldn't really recommend it.


I personally think your case might be a design flaw. Why would you want to take all resources from form page and move them to other? Isn't easier to work with your data in a file / class designed for it and then just decide what outcome you have? If something fails, it returns the user on page with form and if everything went well, you post the data to DB and show overview page with some happy message that everything went okay.

If you really want to proceed with the way of sending everything to other page, using AJAX/AJAJ could be another solution for you.

Ondrej Slinták
Hi Ondrej, thanks for the feedback. Just to clarify a possible misunderstanding: I don't want to process the data on a different page - I want them to be processed by the same page/class which allows them to edit the data. The redirect would come into play afterwards, in order to address the two numeric bullets at the end of my question.
MicE