Note that there are some explanatory texts on larger screens.

plurals
  1. POHow best to pass a message for the user between pages
    text
    copied!<p>So the chain of events is:</p> <ol> <li>The user submits a form.</li> <li>During the processing of the submission, there is a message generated, such as "Your record was saved."</li> <li>The user is redirected to a new page, say the search results.</li> <li>The new page needs to display the message.</li> </ol> <p>So, the question is how to get the message from step 2 to step 3? This is only one simple example...there are many other much more complicated examples.</p> <p>I am using PHP.</p> <p>Needs:</p> <ul> <li>supports multiple messages and need to be formatted on the receiving machine as required</li> <li>messages can be added on the same page (such as within step 4)</li> <li>messages added from inside any function or object</li> </ul> <p>Some options I have come up with:</p> <ul> <li>store in a session variable as an array and emptied after each display</li> <li>pass as a get or query parameter; can get annoying as you are constantly processing this and have to remember to get it; as it can get long, it could easily go over the max length of the query string</li> <li>store in the database on a per session basis (may not always be for a logged in user); this would require an extra insert on each page where they are added, possibly multiple, and an extra select on every page</li> </ul> <p>Currently I have been storing the messages in the session in an array, but I'm wondering if there is a better way. I don't think the other 2 options above are very good.</p> <p><strong>Edit:</strong> I use 2 functions for the session method: AddStatusMsg() (adds an element to the array) and DisplayStatusMsg() (returns an HTML formatted message and empties the array).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload