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'"; }

In reply to Re: How to avoid "Page expired" going back to post-CGI form confirmation? by varian
in thread How to avoid "Page expired" going back to post-CGI form confirmation? by punch_card_don

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.