Copy link to clipboard
Copied
After a form is submited and inserted to the database, if the user hits the
refresh button the data is again inserted to the database (there is a popup
message about re-inserting the data, but if the user clicks ok, then it gets
reinserted again)
How can I prevent the data from being reinserted again?
Thanks
Copy link to clipboard
Copied
There are several options that are well discussed and blogged.
My favorite is a session variable. Set a session variable when the form is generated, then as soon as the from is submitted change the value of this session variable. Then don't process any future form submission requests if the session variable has the updated value.
Copy link to clipboard
Copied
page.cfm
submits to page-act.cfm which does the insert/update/delete (it does not display any output)
page-act.cfm does a <cflocation> back to page.cfm?msg=thanks
page.cfm now shows again, with the updated data and a "thankyou" message based on the fact that your url variable exists.
Copy link to clipboard
Copied
My preferred method is to do it with the insert query.
insert into table (field1, field2, etc)
select distinct value1, value2, etc
from some small table
where you don't already have a record.
Copy link to clipboard
Copied
I just cflocation the page back to itself once I've done the insert. Simple and effective.