Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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 http://www.w3schools.com/, POST (Wikipedia), and use CGI; for a decent head start.


Comment on Re: How to prevent a Reload from resubmitting a form?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043082]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-09-16 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (51 votes), past polls