I had a new thought yesterday or the day before, I think it was the day before yesterday. It has to do with the problem of users hitting submit more than once. Basically, your web browser is an application that is "stateless." It doesn't maintain some sort of connection between the browser and the server at all times (this statement is a simplification). So, if you click submit on a web page link or on a form and the web server at the other end doesn't respond, then you might click again. Since you just clicked "post & publish" on your blog twice before you got a return, you get two identical entries. The receiving server understood the two posts as two separate requests and responded appropriately.
In this context you might think this is a bug, however in reality it is a feature. If the web wasn't set up this way, you would have all sorts of problems establishing connections and so forth before you could read something as simple as this blog. Since the link of connections that brought this text from the Blogger servers to you is tenuous from the get go, you really don't want a statefull connection.
There are a number of techniques to maintain a pseudo-statefull link between the browser and server, such as cookies, sessions, javascript and the like. These are great, but they aren't very simple. You may have clicked submit a couple of times in Blogger and found out that even though Blogger remembers you when you return, it will still let you make a double entry. So in thinking of a simple solution for this problem I thought up this:
- Form contains a hidden field with a random string based on time as the value.
- On submit, the receiving web server looks for the random string (and some other piece of form information in the same record) in the database table(s) the data is going into.
- If the string is not present, then the server inserts the record and returns the response.
- If the string and other piece is present, the server just looks up the record and returns the response as if nothing happened. I don't know if this is a new thing, and I have been using a variation on it for ms150.org e-commerce, but it is a new thought for me.
Using this method, the user never knows if they hit submit once, twice, thrice (chicken soup with rice), and they don't need to know. They just need the return response to know their information was submitted.
-art
No comments:
Post a Comment