punch_card_don has asked for the wisdom of the Perl Monks concerning the following question:

Multifacetted Monks,

So, I'm generating these great submission-confirmation pages with Template Toolkit: when a user submits their choices through an html form, we process it with cgi.pm, store the results in our mysql db, and return a page confirming all the information they just submitted.

The user's happy, so they click on to another page - but then they have a doubt and hit "Back" on their browser to look at the confirmation page again - and they get the ugly "Warning page has expired" page. "The page you requested was created using information you submitted in a form. This page is no longer available....To resubmit your information and view this Web page, click the Refresh button. "

Of course, if they do hit refresh, it does cause a resubmit, and the system is designed to catch a double submission and throw a warning, not the page they just wanted to double check.

Is there anything I can output with the confirmation page - I'm thinking some kind of header - that will allow the user to go "Back" to the page without the browser thinking it has to re-submit the form, and just pull it out of cache?

Thanks.




Forget that fear of gravity,
Get a little savagery in your life.
  • Comment on How to avoid "Page expired" going back to post-CGI form confirmation?

Replies are listed 'Best First'.
Re: How to avoid "Page expired" going back to post-CGI form confirmation?
by Joost (Canon) on Apr 13, 2007 at 16:40 UTC
Re: How to avoid "Page expired" going back to post-CGI form confirmation?
by varian (Chaplain) on Apr 13, 2007 at 17:28 UTC
    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'"; }