Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: How to prevent a Reload from resubmitting a form?

by rjt (Deacon)
on Jul 08, 2013 at 11:14 UTC ( #1043082=note: print w/replies, xml ) Need Help??

in reply to How to prevent a Reload from resubmitting a form?

But whenever i refresh the page, the the entered values are getting inserted again.How can i prevent this ????

Your form is set up with an HTTP POST handler. Per RFC 2616, POST requests may be non-idempotent (i.e., their processing can affect changes on the server, such as inserting a row into a database). For this reason, browsers (by default) force the user to confirm their intention to re-submit their request with a very conspicuous pop-up.

GET requests, on the other hand, can (in theory) be re-submitted all day long with no change. In practice, however, there is nothing preventing CGI developers from having their GET requests do most of the same things POST requests can, and it's not that uncommon, either. So don't think that switching over to GET will solve your issue.

More to the point, this problem tends to be solved through some combination of Javascript (not always) and a form ID hidden field generated by the server and embedded into the <form> HTML code. The server-side (CGI) code keeps track of these IDs (in RAM, database, whatever), and gracefully rejects any further submissions after the first POST is received. Depending on what the form is for, you can decide whether you'll give the user the option of submitting it anyway, or just throw a big fat error message in their face.

This is not a very Perl-ish response, because while you did have a Perl CGI, the root issue really comes down to a better understanding of CGI. To that end, have a gander at, POST (Wikipedia), and use CGI; for a decent head start.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043082]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-05-24 18:12 GMT
Find Nodes?
    Voting Booth?