[Catalyst] Catalyst FormBuilder plugin on CPAN
Matt S Trout
dbix-class at trout.me.uk
Thu Aug 17 02:33:41 CEST 2006
Nate Wiger wrote:
> All-
>
> I just now uploaded Catalyst::Plugin::FormBuilder to CPAN, which adds
> support for FormBuilder in Catalyst. It's also available here:
>
> http://www.formbuilder.org/download/Catalyst-Plugin-FormBuilder-1.02.tar.gz
>
> Usage is similar to XMLRPC: for those controller methods that contain
> forms, simply associate a ":Form" attribute with them:
>
> package MyApp::Controller::Books;
>
> sub edit : Form {
> # this automatically loads root/forms/books/edit.fb
> # and creates a $c->form object for you
> $c->form->method('post');
> $c->form->messages('messages.fr'); # French errors
> }
>
> The page rendering is handled for you by Catalyst using its Template
> Toolkit hooks. To get a standard form, just call form.render in your
> template:
>
> <!-- root/src/books/edit.tt -->
> [% form.render %]
>
> Or, if you want finer control over the placement of your fields, you can
> directly render your form using FormBuilder methods:
>
> <head>[% form.jshead %]</head>
> [% form.start %]
> <table>
> [% FOREACH field IN form.fields %]
> <tr valign="top">
> <td>
> [% field.required
> ? "<b>$field.label</b>" : field.label
> %]
> </td>
> <td>
> [% IF field.invalid %]
> Missing or invalid entry, please try again.
> [% END %]
> [% field.tag %]
> </td>
> </tr>
> [% END %]
> <tr>
> <td colspan="2" align="center">
> [% form.submit %] [% form.reset %]
> </td>
> </tr>
> </table>
> [% form.statetags %]
> [% form.end %]
>
>
> Thanks for Catalyst, it's great! And it was extremely easy to get
> FormBuilder plugged in. I'm a convert. (If anyone has suggestions on the
> plugin, please let me know).
You're going to hate me for this, but ... wouldn't this be better as a
controller base class rather than a plugin? It would be -slightly- more work
to use but it'd allow it to drop in to any existing app, even one that already
loads a plugin that defines a $c->form method?
--
Matt S Trout Offering custom development, consultancy and support
Technical Director contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
More information about the Catalyst
mailing list