Gossamer Forum
Home : Products : DBMan : Customization :

Avoid duplicate when user hit "Back" after add...

Quote Reply
Avoid duplicate when user hit "Back" after add...
Hi!

New day - new problem.Angelic We have been running a dbman test database for a couple of weeks now. During this time I've discovered several times that duplicates occur in the database. Yesterday I spoke to one of the test users and found the reason: After submitting a new record, they see the result and sometimes they want to edit the result. Instead of using the Edit function, they hit "Back" in their browser do the changes and hit Submit again - resulting in a duplicate. Can something be done about this? Has anyone found a good workaround for this problem?

Thank you.

Regards

Batdilla

http://baatplassen.no

Last edited by:

oktrg500: May 26, 2003, 11:37 PM
Quote Reply
Re: [oktrg500] Avoid duplicate when user hit "Back" after add... In reply to
This may work for you:

Prevent Duplicate ID # due to page Reload

in HTML.PL

Add this to top of your file for reference of changes made:
### prevent NEW ID on reload - added codes in sub html_add_failure

sub html_add_failure {
# --------------------------------------------------------

AFTER:
my ($message) = $_[0]; add:

### prevent dup ID # . . also commented out code in .cgi sub add_record ###
if ($message eq "duplicate key error") {
&html_home;
return;
}
### prevent dup ID numbers ####

In your .CGI: in sub add_record

Add this to top of your file for reference of changes made:
# prevent NEW ID on reload - removed codes in sub add_record

AFTER: # First we validate the record to make sure the addition is ok.
$status = &validate_record;

##### comment out the following to prevent a new ID # being assigned when the form
is reloaded ####
## We keep checking for the next available key, or until we've tried 50 times after which
we give up.
# while ($status eq "duplicate key error" and $db_key_track) {
# return "duplicate key error" if ($counter++ > 50);
# $in{$db_key}++;
# $status = &validate_record;
# }

This is fully tested and works great!

-----
You could also provide a link within the record to go directly to the modify screen such as:

|;
print qq!<A HREF="$db_script_url?db=$db_setup&uid=$db_uid&modify_form_record=1&modify=$rec{$db_key}">Modify Record</A> ! if ($per_mod);
print qq|

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Avoid duplicate when user hit "Back" after add... In reply to
Sorry for not replying before. I've been very busy (Who hasn't?). I'll try the suggested mod when I get the time and report back here when done. Thank you.

Regards

Batdilla

http://baatplassen.no