in reply to How to avoid "Page expired" going back to post-CGI form confirmation?

The refresh warning is intentional browser behavior to avoid users to resubmit (but then you're right in that they might still hit refresh and resubmit anyway).

A workaround is to replace the usual submit with an XMLHttpRequest call that performs a similar post action underneath the surface. In this case the original page remains available and the user can press Back/Forward buttons without accidental re-post and associated warnings.

To accomplish this XMLHttpRequest call within Perl you can use module CGI::Ajax
Try the code below as an example:

#!/usr/bin/perl -w use strict; use CGI::Ajax; use CGI qw(:all); my $cgi = new CGI; my $pjx = new CGI::Ajax('submitted_formdata' => \&process_formdata); print $pjx->build_html($cgi,\&show_some_html); sub show_some_html { return <<'END_HTML'; <html> <head><title>Form without post warnings</title></head> <body> Please fill in the form: <form method="POST" > Your name? <input type="text" name="surname" id="surname"> <input type="button" onClick= "submitted_formdata( ['surname'],['response1'],'POST');" value="Submit"> </form> <div id="response1" name="response1"></div> <p> To view some other page goto <a href="http://www.perlmonks.org">Perlmo +nks</a> <br>Then try back button </body> </html> END_HTML } sub process_formdata { my $surname = shift; return "Thank you for submitting your surname as '$surname'"; }
  • Comment on Re: How to avoid "Page expired" going back to post-CGI form confirmation?
  • Download Code