On some critical apps, we use both JS and my server side solution.
One thing I def can state with confidence from experience. You should never rely on JS when it is critical. Always use server side solutions when the application is a critical one, and what is more critical than taking orders.
As a further note, one of the easiest ways to do this in mysql, and mssql, is to use a function each have. On mysql its called:
LAST_INSERT_IDI am doing this off of memory, so you may have to check me. But both mysql, and mssql have a function like this. This function, will return the last inserted auto-increment value for the current session. It is important to make sure you use the function that is tied to the session scope.
Anyway, early in the order process, you just create an order using witango insert action, and the very next action, is a directdbms action that performs the above function, and you have the unique id for this order in a user var.
If you are using a db that does not have a function like this, it is trickier. Do not make the mistake of doing an insert, and asking for the last ID doing something like select max(rowid) from table. This works, but it is NOT full proof. If there are 2 orders happening at the same time, you can get the wrong value, and have 2 sessions pointing to the same order. So, create a GUID (guaranteed unique identifier) and either use that as the order key, or use it to retrieve the order id if you want to use the nice integer id.
So early in the order process, create your GUID in memory and do an insert on your order table. then do a select orderid where guid = 'myguid' and you safely have your order id that way.
As far as creating GUIDs, the best method I have found is use the host OS. They all usually have some form of createGUID. On windows, do a google search for GUIDMAKR. It is a simple com object that works with witango that I have been using for years.
Anyway, early on I struggled through some of these techniques, before I developed fullproof methods, so I hope this helps.
-- Robert Garcia President - BigHead Technology VP Application Development - eventpix.com 13653 West Park Dr Magalia, Ca 95954 ph: 530.645.4040 x222 fax: 530.645.4040 [EMAIL PROTECTED] - [EMAIL PROTECTED] http://bighead.net/ - http://eventpix.com/ On Feb 11, 2007, at 8:17 AM, Alan Wolfe wrote:
Robert's solution is a good one because some people might not have javascript enabled, or their browser might malfunction if they are using a buggy one (happens alot more than you'd think), or if they have spyware or a virus. When you protect it server side, you have alot more control over things. You might try implementing both solutions so that you are well protected from the server side checks while your user understands visually that their order is being processed when the button disapears. Or you could disable it instead of making it go away completely and make it say "Processing..." like this: <input type=button value="Click Me" onclick="this.disabled='true';this.value='Processing...';"> On 2/10/07, Robert Garcia <[EMAIL PROTECTED]> wrote:______________________________________________________________________ __javascript not allowing second click is one way.... Another, is don't use a autoincremented integer as the unique key of the order, or get it from the DB, before you insert. So if in your process, you ASSIGN a order id, and store as a user var, before inserting order, then on submit, if submit second time, it will fail due to unique id contraints. An easy way to do this, is before submitting order, earlier in the process, make an order, by inserting a bit of info, and have a field, called COMPLETE as boolean. on the first submit, make sure you set complete = false. Now you have a ready order in the db, and an order id, even if you use autoincrement. on the final submit, UPDATE that order, and set complete to Y. There are other ways to skin it, but 2 step order like this is pretty damn foolproof. I have a couple of sites that take millions of dollars of orders, one, 2 million a day at times, and have never seen a dupe, because of a variant of the above method. But in my early days, it happened enough to piss me off. ;-) Just remember to have a process, at the end of each month or so, to purge incomplete orders. HTH -- Robert Garcia President - BigHead Technology VP Application Development - eventpix.com 13653 West Park Dr Magalia, Ca 95954 ph: 530.645.4040 x222 fax: 530.645.4040 [EMAIL PROTECTED] - [EMAIL PROTECTED] http://bighead.net/ - http://eventpix.com/ On Feb 10, 2007, at 11:13 AM, Dan Stein wrote:> I have a very complicated taf that is used to process the orders on my> clients site. > > I guess we have been lucky so far. But seems like last month at > least one > person hit the submit button twice looks like they might have even > found a > way to do it before the page refreshed. > > It made a duplicate order record and made a mess of the second > order so it > was actually everything twice. > > I have not figured out how that could happen yet. > > But what is the best way to prevent the submit button from getting > hit twice > if in fact they are going to do it even before page refreshes. > > Of note there are at least 3 different forms on this page. > > > -- > Dan Stein > FileMaker 7 Certified Developer > Digital Software Solutions > 799 Evergreen Circle > Telford PA 18969 > Land: 215-799-0192 > Cell: 610-256-2843 > Fax 215-799-0192 ( Call 1st) > FMP, WiTango, EDI,SQL 2000, MySQL, CWP > [EMAIL PROTECTED] > www.dss-db.com > > Men do not care how nobly they live, but only how long they live, > although > it is within the reach of every man to live nobly, but within no > man's power > to live long. Brian Haig Private Sector > > >> _____________________________________________________________________ _> __ > TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf >_____________________________________________________________________ ___TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.tafTO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
________________________________________________________________________ TO UNSUBSCRIBE: Go to http://www.witango.com/developer/maillist.taf
