------------------------------------------------ On Mon, 21 Jul 2003 17:05:57 -0500, Peter Fleck <[EMAIL PROTECTED]> wrote:
> I have a cgi that creates a form and then receives the output of the > form and sends it to a mysql database. It also displays the form > information as a preview of what is getting sent to the database. > > You can return to the original form with data if you need to correct > something via an 'Edit' button. This button also makes sure that > nothing gets stored in the database (by deleting the data that was > just sent and I know there must be a better way to do that part but > it's not my current question). > > If the visitor uses the browser 'Back' button to return to the form, > their data will be there but the record won't get deleted from the > database. > > How do I erase all the data from the form if the visitor chooses to > use the Back button? I tried the CGI.pm method mentioned in > O'Reilly's CGI Programming: > > print $dataIn->header( -type => "text/html", -expires => "now"); > > but that doesn't do it. > > I'm wondering if javascript is the answer? > I think the difficulty you are experiencing in your implementation is a direct result and indicator of a design that needs to be re-examined. You are running into the standard problem with a protocol that is stateless (aka HTTP). Rather than switching to use Javascript to handle the "abnormal" use of the browser's back button, you would be better off assuming that 50% of the time that is how a person is going to navigate and do something like store the values as hidden fields in a form on the preview page, then when they use the back button make some edits and resubmit, your script need only re-display the preview page, which makes the implementation easier. Then the data is *only* stored to the DB once the final version is submitted from the preview page. To implement your "edit" feature you need only return them to the original form and pre-fill the fields based on the values submitted in your preview form (which is also your "Edit" form). Sorry if this is confusing, I would re-examine why and when you store data to the DB in your design rather than the implementation details. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]