Saturday, July 11, 2009

Success Messages

In almost all of my web sites I have setup forms on our site so that upon submitting successfully, they would either show the success message at the top of the page you were just at or show only a success message on the page and nothing else. While this wasn't the best practice, I couldn't think of a better route to take. My partner recently presented a new idea. Instead of doing it that way and requiring more user input as to what the next step would be, he suggested that we use session variables to store the success message and forward the user to a page they would likely want to be on. So when sending an email, rather than loading a page that just says "Email Sent!", we forward them back to their inbox and show the success message there.
When doing this in PHP, if you use a header() forward your session variable will not save unless you force PHP to write the session. To do this, you would use session_write_close().
$_SESSION["success"] = "Your email has been sent"];
session_write_close(); //without this, the session variable will not be saved before header() executes


No comments:

Post a Comment