• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Prevent inserts into database within 5 seconds

Participant ,
Feb 25, 2024 Feb 25, 2024

Copy link to clipboard

Copied

I have a form that submits to a database.

 

Sometimes users inadvertanly click the submit button 2 or 3 times, resulting in 2 or 3 dupkicate submissions.


I would like to stop users from being able to insert any record within 5 seconds of the last insert


<cfquery datasource="#APPLICATION.ds#" name="get_max_ID">
SELECT MAX(insert_time) AS maxtime FROM FORMS
</cfquery>

When a form is submitted I need to check if it is within 5 seconds of the maxtime .

 

If it is . I <cfabort> with an error message.

 

If it is after 5 seconds I allow the insert.

 

How do I do this check?

Views

169

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2024 Feb 25, 2024

Are you envisioning a db solution? I'd recommend against it. It just doesn't feel like the right way to go. (Maybe you didn't mean that. Just clarifying.)

 

Are you envisioning instead a coldfusion solution? That would be possible, using some way to track the time of each submissions for each user, which could be tracked via sessions, cookies, a database, or even in the application scope (tracking each user there, somehow). It would then just be a matter of using the CF datediff function to comp

...

Votes

Translate

Translate
Community Expert ,
Feb 25, 2024 Feb 25, 2024

Copy link to clipboard

Copied

Are you envisioning a db solution? I'd recommend against it. It just doesn't feel like the right way to go. (Maybe you didn't mean that. Just clarifying.)

 

Are you envisioning instead a coldfusion solution? That would be possible, using some way to track the time of each submissions for each user, which could be tracked via sessions, cookies, a database, or even in the application scope (tracking each user there, somehow). It would then just be a matter of using the CF datediff function to compare the saved time of the last submission to now().

 

But finally this is a kind of problem often solved instead on the client end, using Javascript. Here again there are multiple such solutions (including the simplistic cfinput type="submit" validate="submitonce".) And of course, developers well beyond cf seek such client-side solutions, which widens the range of options you might find. 

 

I realize you may say you'll take any solution that "works", and in that case you may just want to "see some code" for it. But before I or others might offer that, I wanted to put these options out there as a first response, to see if you may point to a preference of one direction vs another. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 26, 2024 Feb 26, 2024

Copy link to clipboard

Copied

Thank you Charlie. I was hoping to use CF code for a solution.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2024 Feb 26, 2024

Copy link to clipboard

Copied

So you'll be using one of the several cf solutions I posed?  Will you take those ideas and run with one?

 

Or are you wanting someone else to write the code? I'm not aware of any that exists, that I can just point to. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2024 Mar 01, 2024

Copy link to clipboard

Copied

LATEST

I'm having the same issues in our application and am brainstorming a plan for this.  We have to dedupe these items a few times per day.

I agree with Charlie about not implementing this at the database layer.  What I'm considering is locking the button and showing a "Please wait..." modal dialog over the page with a small animated gif with javascript that fires when the "submit" "onClick" action is performed. Something similar to, but not necessarily this..  (found it on a quick giphy search)
giphy

 

Then we either wait a set amount of time to disappear, wait for the page to load on the next step after the query finishes to disable it, or find a way to get a callback from the database that the record was written to disable the modal overlay and move the page along to the next step.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation