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


I am designing a form with lots of fields. Most of the fields are required. When a user clicks the submit button, I must use a perl script (not use javascript to do client verification) to verify if all the required fields are filled in or not. If not, it generates some information and gives the user back the incomplete form. After the script checks all the required fields filled, it gives "Thank you". At this time, I don't want the user to click the back button and submit again. Is it possible to display a blank form after the back button clicked? Thanks.

Replies are listed 'Best First'.
Re: Back button to blank form
by vroom (His Eminence) on Feb 20, 2001 at 10:02 UTC
    One way would be to set the expires header of the generated script to the time the page was generated and hope the browser does the right thing. A better solution is probably adding a unique value in a hidden field every time the page is generated. When an item is submitted log that unique key as having been used. If a user tries to submit again with the used key short circuit the process.

    vroom | Tim Vroom | vroom@cs.hope.edu
Re: Back button to blank form
by kschwab (Vicar) on Feb 20, 2001 at 11:53 UTC
    You may find that poisoning the second page load is a major annoyance to your audience.

    Consider that browsers reload the page when asked to print. Go ahead and detect the second load, and avoid a duplicate submission, but display the same data.

Re: Back button to blank form
by eg (Friar) on Feb 20, 2001 at 10:04 UTC

    No, because what's displayed in the form is browser-dependant. One thing you can do is have the script send small page with a meta-redirect to the "Thank You" page on success. That sort of prevents people from clicking "Back" to get to the form. It's imperfect.

    Another technique to consider is to have a hidden "id" field in your form. The "id" would be unique (generated from a counter, say) so if someone tried to submit the same form twice, they'd get an error. This is also imperfect, as it can be spoofed (i.e. someone can manually change the "id" field), but perhaps for your application that's all right.

Re: Back button to blank form
by Chady (Priest) on Feb 20, 2001 at 23:43 UTC
    I guess that you can use an event handler in your page where the form is :
    try this code <body onLoad="document.forms[0].reset()">

    just make sure that you put a reset button for Netscape..
    and it is worth to note that this isn't tested for all browsers and again you're depending on the browser to do the job, so it's not quite good


    Chady | http://chady.net/