[Catalyst] Design of a new form validator
Sebastian Riedel
sri at oook.de
Thu Dec 1 00:15:17 CET 2005
I've started implementing yet another form validator, main goals are
elegant syntax and integrated xml generator.
Features on the todo so far:
* Pluggable element/constraint support
(HTML::Widget::Element::Textfield, HTML::Widget::Constraint::String...)
* Both validation and xml generation are optional
* Clean xml output (easy to style with css)
* Chained accessors (makes complex data look simple)
* Extendable enough to support all kinds of Ajax hacks
* Client side JS validation
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.');
my $form = $w->process;
my $form = $w->process($query);
[% form.as_xml %]
[% FOREACH element = form.errors %]
<p>
[% element %]:<br/>
<ul>
[% FOREACH message = form.messages(element) %]
<li>[% element %]:</li>
[% END %]
</ul>
</p>
[% END %]
<p><ul>
[% FOREACH element = form.errors %]
[% IF result.error( element, 'Integer' ) %]
<li>[% element %] has to be an integer.</li>
[% END %]
[% END %]
</ul></p>
The output of as_xml() is not yet defined, need a designer to create
a simple easy to theme form.
And no, there are no alternatives on CPAN that fit all my needs.
--
sebastian
More information about the Catalyst
mailing list