ZForm HTML form management
download ZForm
User manual (incomplete)
ZForm module documentation
Sourceforge page
What is ZForm?
ZForm is a set of Perl modules that make the development of
web-based forms much simpler and allow the programmer to get on
with the real meat of the application.
How does ZForm Work?
When developing web applications, I find that I each form that I
write needs to follow the exact same logic:
1. Display blank html form with default values
2. Validate form after submission
3. If form does not validate, redisplay form with errors. Be
sure to preserve values so that the user does not need to reenter data.
Go back to 1.
4. If form does validate, do something with data, and maybe go to next
form.
This process is tedious and time consuming. The interesting work is in step
4, but I spend all my time on steps 1-3!
ZForm aims to make steps 1-3 easier
Step 1: Forms can be auto-generated or be defined using HTML::Template.
The HTML for the input fields is always generated. This makes it easy
for ZForm to maintain state between validations and also allows one
to use the same exact template for a data-only view.
Step 2: Validation is a very important step. This is where we
verify that the application is receiving
clean data and also where the application keeps malicious users
from doing nefarious things with our
form. This process is almost exactly the same each time. Verify that:
- required fields are present
- popup menus, radio groups, etc have values that are allowed
- text fields match regexes
Step 3: Redisplay the form if validation fails. ZForm makes things simple
by turning this into step 1 with error messages.
Step 4: Perform application logic. ZForm leaves the fun to you!
Why did you write something new?
After evaluating the existing form validation perl modules, I found the
following to be issues:
- Not easy to maintain the state of the form after a failed
validation.
- Either the HTML could be completely generated, or you had to generate
it all yourself. This means that to maintain state after a failed validation,
one either has to place perl code within the template, or put HTML within
the perl code. While a certain amount of this will happen no matter
what one does, I want to minimize this ugly issue.
- Basic validation was present, but either not easily extensible, or (in my
opinion) requires one to type too much stuff. For example, a popup menu
only requires one form of validation: the submitted value must be one of
the values on the menu. I did not see any packages that performed this
check.
- Automatic generation of an HTML::Template compatible templates from
a form definition.
- Form fragments. I want to be able to define form fragments, such
as a phone number form, and include that in other forms. This allows one
to define a single phone number form and the validation of that form
and reuse it all over a website.
- Validation on the contents of multiple fields. All modules I evaluated
only perform validation on a field by field basis and no easy hooks
to change this behaviour. Sometimes, you need
to validate a form based on the contents of multiple fields. For example:
assume that a form asks for your country and postal code. If you answer
"US" in the country field, then the postal code field needs to be
of the format DDDDD-DDDD. However, this is not the case for countries
outside of the US.
- Not a missing feature, but an extra feature: most existing modules
will generate the HTML, but generate it themselves. Why not use the CGI
perl module? Just a minor nitpick, but it allows me to support all of
the fields that CGI.pm supports without writing very much code.
Who makes this possible?
My employer, ZiaNet , makes
this possible. I need to develop some web-based perl applications
and this library is the basis for those applications. Anthony, the
owner of ZiaNet, was gracious make this project freely available.
TODO List
- More documentation.
- Test, test, test.