开发者

How to implement a time wait before html form resubmission?

I have an html form which inserts data into a database. I just built it.. it's very basic, as I'm just doing this to learn. In doing this, I see that I can hit the back browser button and post again.. and again.. and again.. and it keeps writing to the db.

I've seen sites where I try to resubmit info and it tells me I must wait 60 seconds (or whatever)开发者_Go百科. Is this the preferred method to solve this problem? If so, how does one go about implementing it?

Or maybe you would handle it a different way?


When you insert a row, store the submission time in the table, or in the user's session.

Whenever you process the form, compare that time to the current time. If it's within 60 seconds, display an error instead of inserting a row.


There are two methods :

i) Simple client side javascript: Store the time of last event in a javascript variable, when the user does the event again , send an alert message about timing. ( This method can be fooled though by users knowing javascript )

ii) Store the time of last event in your database at backend when the form post is done. When the same form post is done again, check for the time, if it is allowed, do the processing, else reply with a message about the timing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜