I have functions, set_sessionMessage() and get_sessionMessage(), which allow you to give responses to form actions after a redirect (thus clearing the POST data).
The general logic may be something like this:
- Show form
- On submit, error check, show form populated with user data on failure
- If valid data INSERT, set_sessionMessage, redirect back to same page
- If get_sessionMessage() display it
So I use 1 script for error messages, sucess messages and to process the form.
The script just looks for a form submission, or a previously stored sessionMessage to display. After successful submission the user can refresh or go back without reposting the form.
get_sessionMessage also REMOVES the message from the session after returning it, so that it isn't displayed the next time the page is loaded (unless another form submission is made).
It's also a good idea to draft off all your long winded form validation, processing and presentation logic to separate classes/functions so you don't end up with a monster procedural script with 1000 lines of code. Very hard to maintain and understand. Also avoids having huge if, else() blocks.
Bookmarks