Review Web Form Entry Before Final Submission

Review Web Form Entry Before Final Submission

am 17.03.2005 20:11:14 von dsdavis

Hi,

I write a lot of programs in Perl that display a web form, and the user =
then
fills it in, and I like to give them a chance to review the information =
that
they've submitted and have the opportunity to go back (via the Back =
button
in their browser) to make changes before the final "set in stone"
submission.

What's the best way to do this?

What I've been doing is this:

A Perl script creates the form (or sometimes it's just a standard HTML
page).

The user fills it in then clicks "Preview" or some such button.

The form data is processed by a ReadParse subroutine from cgi-lib.pl and
then spit back out as a webpage to show the data the user submitted.

The data is also in a form on that page with all of the data as hidden
fields which if they click Submit will then be sent to a MySQL database. =
=20

If they click the Back button in their browser instead of Submit, they =
can
make changes, Preview and Submit/Edit again ad infinitum.



It's rather tedious to have to spit their data back at them and have it =
all
in a form as hidden fields, but I haven't figured out a better way to do =
it.

I'd like to have the data go to a MySQL database when they click =
Preview,
and then if they click Back and edit the info, the data in the database
would just be updated, but how would I do that? They'd have to get some
type of unique ID that would be present in the page when they go back to =
it
or it would have to be present when they first load the web form so that =
the
data could be matched up.

I'm sure there are much better ways to do it than what I'm doing. =
Please
enlighten me.



Douglas =20


--------------------------------------
Douglas S. Davis
Programmer/Analyst
Haverford College
Department of Administrative Computing
370 Lancaster Ave.
Haverford, PA 19041
610-896-4206
dsdavis@haverford.edu
http://www.haverford.edu=20



--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=3Dgcdmp-msql-mysql-modules @m.gmane.org

Re: Review Web Form Entry Before Final Submission

am 17.03.2005 20:33:58 von Sean Quinlan

--=-4uWBigG6vga0D0BjBD+c
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Thu, 2005-03-17 at 14:11 -0500, Douglas S. Davis wrote:
> Hi,
>=20
> I write a lot of programs in Perl that display a web form, and the user t=
hen
> fills it in, and I like to give them a chance to review the information t=
hat
> they've submitted and have the opportunity to go back (via the Back butto=
n
> in their browser) to make changes before the final "set in stone"
> submission.
>=20
> What's the best way to do this?

I've usually used a cookie. If the size of the information or security
considerations are such that that's not feasible, then I return an md5
hex key as the cookie and store the input in the DB with that as the
key. I generally just use %params =3D $cgi->Vars; to get the form data and
stringify %params with Data::Dumper. Some field types can require
special handling and of course YMMV.

I also have a little toolbox of functions for generating dropdowns,
radio buttons and such so I don't have to rewrite adding "select" to the
appropriate options in the HTML over and over.

> What I've been doing is this:
>=20
> A Perl script creates the form (or sometimes it's just a standard HTML
> page).
>=20
> The user fills it in then clicks "Preview" or some such button.
>=20
> The form data is processed by a ReadParse subroutine from cgi-lib.pl and
> then spit back out as a webpage to show the data the user submitted.
>=20
> The data is also in a form on that page with all of the data as hidden
> fields which if they click Submit will then be sent to a MySQL database. =
=20
>=20
> If they click the Back button in their browser instead of Submit, they ca=
n
> make changes, Preview and Submit/Edit again ad infinitum.
>=20
>=20
>=20
> It's rather tedious to have to spit their data back at them and have it a=
ll
> in a form as hidden fields, but I haven't figured out a better way to do =
it.
>=20
> I'd like to have the data go to a MySQL database when they click Preview,
> and then if they click Back and edit the info, the data in the database
> would just be updated, but how would I do that? They'd have to get some
> type of unique ID that would be present in the page when they go back to =
it
> or it would have to be present when they first load the web form so that =
the
> data could be matched up.
>=20
> I'm sure there are much better ways to do it than what I'm doing. Please
> enlighten me.

As mentioned above, variations based on the concept below, storing the
key as a cookie or hidden field as appropriate.

Dumper to turn a data structure (all the form values) into a string that
can be later eval'd back into a data structure:
http://search.cpan.org/~ilyam/Data-Dumper-2.121/

md5_hex to generate a unique key based on the data.
http://search.cpan.org/~gaas/Digest-MD5-2.33/

Both of those modules should already be installed on your system.

Quick example:
my %params =3D $cgi->Vars;
# if you don't like getting %params from $cgi, you can just list all
# values as you have them and their names in Dump
my $param_dump =3D Data::Dumper->Dump([\%params],["*params"]);
my $now =3D localtime;
my $key =3D md5_hex("$param_dump,$now");

HTH
--=20
Sean Quinlan

--=-4uWBigG6vga0D0BjBD+c
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBCOdumnv2yYfTgGZsRAnosAJ96FQmDndus4XC/kyy7vQ2ZySkhOwCg hdUQ
DJEg3wKpxenJhagjNbPENlw=
=h9xj
-----END PGP SIGNATURE-----

--=-4uWBigG6vga0D0BjBD+c--