note 104519 deleted from session.examples by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Jun 2011 17:16:41 +0000 |
| Subject: | note 104519 deleted from session.examples by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180795@lists.php.net to get a copy of this message | ||
Note Submitter: briank at kappacs dot com
----
Chris,
You can also use the "GET-after-submit" design pattern:
# Perform your POST or GET form processing here
header("Location: $next_page_url");
If the user reloads the page (either through a refresh or history navigation), it will be the
$next_page_url that gets reloaded.
I typically use a sequence that looks something like:
# Process the form, then...
App::notice("Thank you for your form submission.");
$status = App::saveStatus();
header("Location: $next_page_url&status=$status");
exit();
App::notice (and App::error) are methods in a custom application object for recording responses to
be presented to the user in a page template.
App::saveStatus() moves all accumulated notice and error status into a time-indexed part of the
session and returns the time index.
When a status parameter appears in a request, my request dispatcher checks for a stored status
message with the specified time index. If found, the content is moved from the session back into the
application object.
Thus, any form action is only performed once, and any associated response is only displayed once
(the first time $next_page_url is loaded after the form is processed).