Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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?

Comment on HTML Form Validation
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?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (10)
As of 2014-11-20 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (102 votes), past polls