I was wondering if coldfusion could be used to ensure that a user submits the information in a form just once, and prevent multiple submissions of the same data.I tried using javascript, but it didnt solve the problem.
Thanks
ahksar
You could set a session variable such as "session.formSubmitted" to "yes" for the first submision. You could then check to see if "session.formSubmitted" exists and not process the submission if it does.
I believe this should do what you want.
<cfif isdefined("session.formSubmitted">
..... Put a message saying they've already subitted, redirect to another page, etc...
<cfelse>
.... Code to handle the submission .......
<cfset session.formSubmitted = "yes">
</cfif>
This method assumes the visitor will only need to fill out the form once, if multiple submissions of different data is necessary, you'll have to add some coding to clear the session variable.
GunJack, I think ahksar means that he wants to prevent impatient users from submitting one and the same form a couple of times (is that right ahksar?). You know, if it takes some time before the form is actually submitted, some users keep on clicking the submit button hoping it will speed things up .
ahksar, the following Javascriot can be used prevent this:
<SCRIPT LANGUAGE="JavaScript">
var submitted=0;
Yea, I've used JS to prevent duplicate submissions but I've found it's not always reliable. Since he said he didn't have good luck with JS and asked for a CF solution, I posted one which I believe will work. Anytime I use JS to prevent the user from doing something undesireable on the client side, I like to have CF double check and prevent it as well on the server side in case of a JS problem with earlier browsers or if they have it turned off altogher.
One of the simplest JS check routines I've seen was this,
i agree with GJ, the CF solution is safer, but it's faster for the user to also have a simple jscript that reacts - that's why i also use both (a very light jscript, as the one you're mentionning or the disable trick if i'm sure of the user browsers; and then the session stuff in cf)
I had already tried the code iqof said, and while it worked , people could still submit the form more than once. DEfining a session variable worked though. Thanks for all your help.
ahksar
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.