CGI form repost from browser--how to prevent?

dsavitsk dsavitsk at e-coli.net
Tue Dec 11 14:34:28 EST 2001


how about using JavaScript?

make the submit for your form something like
<a href="JavaScript:Submit_My_Form();">Click Here to Submit.</a>

add an element like this to the form
<input name="have_they" type="hidden" value="no">

then add a function like this to the Head

<Script Language = "JavaScript" type="text/javascript">
 function Submit_My_Form();
  if (document.My_Form.have_they.value == "no") {
      document.My_Form.submit();
      document.My_Form.have_they.value = "yes";
      }
  else {
      window.alert = "Do not press that again.";
      }
  }
</Script>

something like that should work ... i think?

"Chris" <bit_bucket5 at hotmail.com> wrote in message
news:fa7108b0.0112111051.3a9585c5 at posting.google.com...
> I'm writing a Python cgi script that does some inserts into a mysql
> database based on data in an html form submitted by a user.  Is there
> any way to prevent the browser from reposting the data from the form
> when the user hits refresh in the browser after they have submitted
> the form?  When this happens, the script receives the same cgi form
> data and performs the same inserts on the database.  I think maybe
> this can be prevented by storing some state info with cookies??  Not
> sure (have never used cookies).  Any ideas on an easy way to prevent
> this?
>
> Many Thanks.
>
> -Chris





More information about the Python-list mailing list