pandah
Posts: 1
|
Posted: 01/25/2010, 5:35 AM |
|
This is a Code Charge Studio Specific Solution (using PHP) to stop users from using browser back button then resubmitting a form which causes duplicate or additional unexpected records.
When a user browses back to a CCS Insert Form, it is still in insert mode from the last insert. If they click Insert again, it will create a duplicate record. If they change details then click insert, it will create a new additional record (not update the details or the original record which is typically what the user is trying to do).
1. Add a Hidden Field anywhere on the Form and name it Submitted
2. Add the following code to the Before Show Event for Submitted Hidden Field
//Generate unique identifier to detect duplicate insert
$Component->SetValue(uniqid());
3. Add the following code to the Server On Click Event for the Forms Insert Button.
if (!$Container->EditMode){ //Only an issue for insert mode. Edit (update) mode not effected
if($Container->Submitted->GetValue()==CCGetSession('last_'.$Container->ComponentName,'')) {
//If the current unique identifier matches the last one stored in the session variable
//then the page has not been reloaded and proceeding with the insert will cause a duplicate.
global $Redirect;
$Redirect='error_duplicate_entry.php';
} else {
//Save the unique identifier for the this currently submitted form in a session variable using prefix and form name
CCSetSession('last_'.$Container->ComponentName,$Container->Submitted->GetValue());
}
}
4. Create an error page such as error_duplicate_entry.php to notify something like:
Error: The System has detected an attempt to create a duplicate entry.
This is usually a result of using the Browser Back button and submitting a form on a previous page again.
The last changes you made before seeing this page have been discarded.
Please use the link below to return to [somewhere]
Please do not use the back button on your browser with this site.
[Link to Somewhere]
If anyone has anything better or can improve this, please post for others to share.
|