I am looking for a “neat” (clean) way to show a status message after submitting a form.
For example, if a user updates their profile, I want to show a DIV with the text “Your Profile Has Been Updated!”.
Right now I am getting this done this way:
After posting the data and either inserting or updating the database table, I do a header(“Location: updateprofile.php?status=updated”);
This works just fine and dandy, however it isn’t very clean. I don’t want the query string.
Another method I tried was to set a variable of $submitted=1; and not do a redirect after. However, when a user is updating their information it still shows the old information in the form fields until a refresh. So this doesn’t work either.
I know I could use AJAX to submit the form and accomplish it that way, however, for what I am doing I do not want to use AJAX. I want a server side solution.
My only other thought is having to set a $_SESSION variable then somehow remove it after showing the status update.
Any ideas would be appreciated!
Thanks,
Tony
Most of the time this is handled through session variables that store whatever flash messages need to be shown.
In a shared view (layout, element) put something like
Set
$_SESSION['flashMessage']to “Your profile has been updated.” in whatever code is handling your form submissions.