If you write CGI scripts that present HTML forms to the user with values filled in, you may like this module. Its main function defaultify() lets you populate any HTML form with default values that you specify-- it parses the HTML to find the tags representing form fields, and alters those tags so that the desired initial values will be set. It's useful in many situations, such as: letting a user correct input errors, presenting a form to edit an existing database record (or user account information), maintaining a query form from one results page to the next, etc. Other tools can be used for this, but they require the HTML to be highly interspersed with program code. HTML::Defaultify lets you completely separate the two, which usually makes management much easier-- a non-technical designer can work on the HTML while a programmer works on the code. Also, it can use any existing HTML, so there's no need to rewrite any old pages in a new format.
The defaultify() function is very easy to use-- just pass it the HTML to defaultify, and your set of desired defaults in a hash. You can create your own defaults hash, or you can use the return values from several existing tools (CGI.pm, cgi-lib.pl, getcgivars(), etc.). Multiple forms, multiple same-named fields, and HTML comments are all handled correctly. Besides defaultify(), this module provides other functions to parse HTML tags and to facilitate and enhance some uses of defaultify().
For complete usage documentation, including examples, see the perldoc of HTML::Defaultify.
First, download the distribution:
As with most Perl modules, install HTML::Defaultify by unpacking the distribution, changing to its directory, and running these commands:
perl Makefile.PL make make test (optional) make install (normally must be done as root)
That should be all you need. The only files installed are HTML/Defaultify.pm, and probably a man page for it.
If possible, you should also install the HTML::Entities module if it's not already on your system. HTML::Defaultify can work without it, but it won't handle character entities other than the four most common ones. If your HTML form fields contain other character entities, they may not be handled correctly without HTML::Entities.
For complete usage documentation, run "perldoc HTML::Defaultify", or see the output of that here.
To read the documentation without installing the module, run perldoc on the Defaultify.pm file with "perldoc -F Defaultify.pm". If your perldoc fails and says it "cannot find blib", then run perldoc from a directory with no Makefile.PL-- it's an apparent bug in some perldoc's.
This software is copyright (c) 1996, 1997, 2002, James Marshall. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|Last Modified: June 17, 2002||http://www.jmarshall.com/tools/defaultify/|