[Handel] Modperl init pb
Andrew Ford
A.Ford at ford-mason.co.uk
Thu Oct 20 18:13:42 CEST 2005
Bernard FRIT wrote:
>2005/10/12, Christopher H. Laco <claco at chrislaco.com>:
>
>
>>Yeah. That means I did something right. :-)
>>
>>
>
>You did it !!
>
>
>
>>How's the project going?
>>
>>
>
>Very slowly (!!) as it's a part time project and I have to glue
>several things together :
>- Catalyst (new for me)
>- Handel (ditto)
>- Glimpse
>- Formbuilder
>- TT2
>
>At the moment I'm experiencing strong drawbacks in glueing Formbuilder
>with Catalyst.
>
>
I have registered the CGI::FormManager namespace for an alternative to
CGI::FormBuilder. Similar sort of API, but the module uses
Data::FormValidator for validation.
The idiom is:
my $fmgr = CGI::FormManager->new(
form1 => { options => { method => "POST" },
elements => [ "<h1>User data</h1>",
text_field(name => 'name'),
text_field(name => 'email'),
select_field(name => 'ctry',
label => 'country',
options => [ [ "" =>
"-- select a country --" ],
[ "GB" =>
"united Kingdom" ],
"US=United States",
...
] ),
...
validation => { required => [ qw(name email ctry) ],
constraint_methods => {
email => email(),
}
}
},
form2 => { ... }),
my $form = $fmgr->form("form1");
$tt2->process('template', { form = $form })
my $results = $form->validate(\%data); # or pass a $cgi object
if ($results) {
# do something
}
else {
@missing_values = $results->missing;
...
Form objects stringify as the HTML that makes up the form, either using
a built in template (which uses tables and CSS for layout) or one
specified in the form options. Results objects are forms, so will
stringify to HTML with value and selected attributes set according to
the supplied data, and will include error messages where validation
fails. This means you can have TT2 templates that just say:
<h1>My form</h1>
some instructions here
[% form %]
The user data is held in the results object when you do a
$form->validate, so it gets discarded when $results goes out of scope,
but the idea is that you store a form manager object in class data of a
Catalyst component, so it only needs to be constructed at server startup.
There is also a $form->confirm which generates a table of the values
supplied, with hidden fields for each data value and confirm, edit and
cancel buttons.
Bool is overloaded for results objects so that they return
$results->success (as with Data::FormValidator objects); forms are false
in a boolean context (although you can say defined($form) if that is
what you want to test).
I am still fleshing out and tweaking the module but am already using it
for a couple of web sites. I hope to have a first version ready to
upload to CPAN within a week or so.
Andrew
--
Andrew Ford, Director Pauntley Prints / Ford & Mason Ltd
A.Ford at ford-mason.co.uk South Wing Compton House
pauntley-prints.co.uk Compton Green, Redmarley Tel: +44 1531 829900
ford-mason.co.uk Gloucester GL19 3JB Fax: +44 1531 829901
refcards.com cronolog.org Great Britain Mobile: +44 7785 258278
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/handel/attachments/20051020/205db85f/attachment.htm
More information about the Handel
mailing list