[Catalyst] Design of a new form validator

Bill Moseley moseley at hank.org
Thu Dec 1 07:35:21 CET 2005

On Thu, Dec 01, 2005 at 12:15:17AM +0100, Sebastian Riedel wrote:
> Here's a mockup:
>     use HTML::Widget;
>     my $w = HTML::Widget->new( { method => 'POST, 'action => '/foo/ 
> action' } );
>     $w->element( 'Textfield', 'age' )->label('Age')->size(3);
>     $w->element( 'Textfield', 'name' )->label('Name')->size(60);
>     $w->element( 'Submit', 'ok' )->value('OK');
>     $w->constraint( 'Integer', 'age' )->message('No integer.');
>     $w->constraint( 'Required', 'age', 'name' )->message('Missing  
> value.');

So are you defining a text field "age" and then adding an Integer
constraint to that field?  Kind of like DFV, where you define a field
and then add constraints on that field?

Seems like there's only a handful of different types of fields.  So,
how about  $w->element( 'AgeField', age ) which knows it should be in
the range of 0 to 200 (with a bit of luck).  And then add additional
validation if needed when you need a specific range.

>     [% form.as_xml %]

Is that the entire form?  I can't imagine that working in most cases
-- forms always seem to need to be customized, so I find that I have
to build the form field-by-field in the template.

One thing I think would be useful is to define reusable fieldsets that
could be put together to make a form.  An example might be an address
that is made up of multiple fields.  Often you might have multiple
forms that include a place to enter an address.  So it would be nice
to define an object that represents an address and can be used on
multiple forms.  Rose-HTML-Objects can build multiple element fields,
but I'm not sure if you can defined "formlets" and connect them
together into a larger form.

Unedited and a bit wordy, but here's my form setup:


Perhaps forms are like templating systems -- everyone needs to write
one once.

Bill Moseley
moseley at hank.org

More information about the Catalyst mailing list