locked_user sundialsvc4 has asked for the wisdom of the Perl Monks concerning the following question:

I need to be able to easily generate HTML forms that do JavaScript validation if JavaScript is installed, but that work just as well if it doesn't. In the usual Perl philosophy of "DRY," I don't want to have to do anything twice ... nor in two different ways.

Note that I do not have a large number of forms to deal with in this case. But... “laziness is a virtue, you know.”

I was rather bemused to see that www.formbuilder.org now has a slug-line at the top of the page, telling us how we all should switch from Perl to Ruby! (Heh.)

I am rather impressed with the JavaScript effect that can be had from the wForms.js library (www.formassembly.com), but I'm mildly-surprised not to see a CPAN module specific to it. (I like the "repeating group" functionality, because that's exactly one thing that I will often need to do.

I see that FormFu has the capability to use templates, which I think would be quite important to me in this application. It also seems to be the most-recently updated module that I have yet seen ... a new update posted just a few days ago. But it's (blink...) rather daunting, and I just don't have a lot of time in which to decide.

War-stories and warm advice are most welcomed...

Replies are listed 'Best First'.
Re: HTML forms ... "whew!" Advice?
by Your Mother (Archbishop) on Jan 08, 2009 at 06:49 UTC

    My comment will likely be more consoling than useful: I've been writing CGI constantly for 10 years and I have never solved this problem in a way I find satisfactory. The client side is a great place for it because it's fast, flashy, and saves server load. The server side is necessary because user input can't be trusted. The presentation/view has to carry feedback; maybe in more than one dialect (XHTML/JSON). The model must be respected (built-in constraints) and the business side of the model must be protected and both will be used is a disconnected from the view/controller fashion so it might end up carrying its own layer. Now we're up to at least three points of validation + exception and feedback handling and let's not even speak of il8n.

    If this were solved right... it would be in a fat model (business logic/constraints built into the model interaction) which exported information and exceptions thoroughly enough to automate the control and view layers completely. There are two points here, there must be a "validate" method in addition to a "create/update" method. I suppose in DBIC parlance, Result->new() would do validation/checking while Result->create_or_update would do that after passing the validation checks in ->new. You see a problem immediately though. Your framework is now married to a model class. FormFu has made some strides here. I've adopted it lately and I'm not sorry yet. Still, it's not hitting the sweet spot that makes me feel like the search is over.

      I just wish that I had a cornucopia of reference-documents right now ... actual, live FormFu examples.

      I'm standing by a dirt road with lots of obvious tire-tracks, so I know that lots of people have passed-by recently. However, what I want to do right now is... “follow that car!!” (Good way to miss the pot-holes.)

      :-)

Re: HTML forms ... "whew!" Advice?
by Popcorn Dave (Abbot) on Jan 08, 2009 at 03:20 UTC
    Is there some reason you can't do all your validation through your CGI? If not, maybe AJAX would be the way to go using the JSON module to interface with your Perl.


    To disagree, one doesn't have to be disagreeable - Barry Goldwater

      The trick is, for this part of the application, the application must work equally well whether JavaScript is enabled or not.

      So, sure... “it's a cut-n-dry form validation chore.” And I'm probing here to find out (as is so-often the case) if “a great solution exists, but I haven't stumbled-upon it yet” among the many thousands of CPAN modules.” :-)

Re: HTML forms ... "whew!" Advice?
by zby (Vicar) on Jan 08, 2009 at 07:01 UTC
    I am not up to date with FormFu - but I did work quite extensively with it in the past and I can attest that using the templates is rather difficult. There is a page on Form processing at the P5P wiki (unfortunately it is not responding right now - so no link).