Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

HTML Form Validation

by zerohero (Monk)
on May 22, 2009 at 06:02 UTC ( #765612=perlquestion: print w/replies, xml ) Need Help??
zerohero has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Mason and creating an HTML form which does validation. The form "POSTs to itself" by passing the same values back, and loading them into the UI elements (e.g. text boxes). It validates each value, and if something is wrong, will color the UI element red (i.e. by adding a CSS error class to the class list).

I've done a simple example by hand just to see what is required.

I'm now looking for a perl class library that helps do these types of simple form validation (posting back, resetting UI values, validating UI, etc.).

Can anyone recommend a good library for this?

Replies are listed 'Best First'.
Re: HTML Form Validation
by CountZero (Bishop) on May 22, 2009 at 06:23 UTC
    There area number of modules that do these things: HTML::FormFu, Form::Processor, CGI::AutoForm, CGI::FormBuilder, Data::FormValidator, ...

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Thanks, HTML::FormFu looks pretty good. It seems to make an attempt at separating the display from the logic. While it's a tad more complicated than the others, it seems to attempt to handle all of the things involved for an HTML form. I'll likely give this one a try.

      Some of the others are aimed at handling just the validation logic, and value transformation. Not a bad thing to handle, but the rendering requires quite a bit of thought too.

      CGI::FormBuilder seems pretty decent and is documented well. The one problem I had was the rigidity in the display area. Since you pass in CSS arguments to the form, it doesn't look like this is separated out nicely (i.e. you'd want CSS classes and then to control layout separately). Perhaps this is just a simple example, and one can separate things (this wasn't clear from the 10 min I looked at it).

        OK it seems that CGI::FormBuilder handles view/logic separation by relying on a templating engine, which seems like a good approach, rather than reinventing the wheel. The injected CSS looks like it's useful for those who want something quick.

Re: HTML Form Validation
by zby (Vicar) on May 22, 2009 at 08:10 UTC
    I am a contributor to HTML::FormHandler - it is a relatively new library (although it is kind of descendant of mentioned above Form::Processor), Moose based, and we have big hopes for it :) It can already do, more or less, what you described.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://765612]
Approved by targetsmart
help
Chatterbox?
[choroba]: I mean, the slides are, but not the makefile with scripts to create them
[Corion]: haukex: I've only now arrived at that revelation ;)
[Corion]: choroba: I use spod5, which also has that support, and also implements its own kinda-make stuff
[haukex]: But that module I just linked to assumes that most verbatim blocks are runnable code, I have other modules where that's not the case, so there I just copy-and-paste the synopsis into the author tests...
[haukex]: not the most efficient, but then again, I don't have that many modules on CPAN :-)
[Corion]: haukex: Yes, but if it's only supposed to run on my machine, I can be far more liberal with how I extract the code etc.
[Corion]: haukex: Yes - I see the benefit of using Dist::Zilla for people with 150+ modules on CPAN, but I don't see it for myself, and I'm always put off from contributing to such modules because they require a lot of toolchain setup that I don't want to ...
[Corion]: ... spend time on if I only want to provide a short patch
[haukex]: Corion: Yes exactly, in the author tests I don't worry about portability as much, I also don't list the author tests' dependencies in Makefile.PL
[haukex]: I figure someone who wants to contribute will know how to install the missing modules ;-) Not the nicest way to go but I don't think many people are using my modules yet

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-02-27 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.