Subject: | Multiple form submission issues |
A collection of patches to address the problem of multiple form submissions (as discussed on the list), as when a user clicks the "reload" button on the browser and ignores the POST data warning, or uses the "back" button and submits again. These patches have no effect if their use is not desired, but if they are, they will ensure that a form cannot accidentally be submitted twice.
Maypole-patch patches Maypole.pm to provide the make_random_id
method. This simply uses and then calls
Apache::Session::Generate::MD5::generate(), which returns
a 32-character random string, and doesn't do any session stuff
at all. (Indeed, putting this in Maypole itself could make it
useful for other things.) If you don't want to use the
A::S::G::MD5::generate, you can manually put in the identical
lines, or it can be overridden easily.
CDBI-patch patches CDBI.pm to provide the guts of the
functionality: if sessions are running, _and_ if the user
is passing around form_id parameters, the form_id value
will be put in the session, and any further form submission
using the same form_id will place an error message (itself
configurable in DriverDB->config->{table_name}{mult_submit_err_msg} )
into $r->{template_args}{messages}, and bounce the user back
to the list template. If the application is not using sessions,
or if it is using sessions but is not using form_id values, then
nothing will happen.
Finally addnew-patch and edit-patch are patches for those
templates in the templates/factory/ directory, in each case
adding a hidden form field named form_id containing a random
id value as generated by make_random_id. Again, it's OK to
put this in the factory templates, since if the user is not
using sessions, nothing happens. (It's also trivially fast
to generate the random numbers; I did a benchmark on a slow
computer and was able to generate 15,000 such form_id values
in one second.)
Message body not shown because it is not plain text.