[Catalyst] subclassing Catalyst::Controller::HTML::FormFu

Carl Franks fireartist at gmail.com
Sun Jan 18 08:52:13 GMT 2009

2009/1/17 Markus Holzer <markus.holzer at dmk-internet.com>:
> Am Samstag, 17. Januar 2009 12:06:33 schrieb Carl Franks:
>> 2009/1/16 Markus Holzer <markus.holzer at dmk-internet.com>:
>> > Hi.
>> >
>> > I have created a subclass Catalyst::Controller::HTML::FormFu because I
>> > want to override the load_form() method. I *think* I have done it right,
>> > but it doesn't work. The load_form method is never called, but FormFu
>> > still works.
>> >
>> > What am I doing wrong?
>> Hi Markus,
>> I think you've been confused by the documentation which gives an
>> example of FormMethod('load_form') as a way to call a method in your
>> own controller, to return a form.
>> If that's all you want to do, you don't need to sub class, just make
>> sure that you use FormMethod() instead of FormConfig(), and that the
>> load_form() method is in your controller class.
>> The reason it's not currently working, is there's no load_form()
>> method anywhere in the FormFu controller code, so nothing's calling
>> it.
>> An example of what I think you should be doing:
>> package Superclix::Controller::Partnerprogramm;
>> use strict;
>> use warnings;
>> use parent 'Catalyst::Controller';
>> sub load_form {
>>     my ($self, $c) = @_;
>>     # returns a HTML::FormFu object
>>     # can get an empty form to start with using $c->form;
>> }
>> sub neu : Local : FormMethod('load_form') {
>>     my ($self, $c) = @_;
>>     my $form = $c->stash->{form};
>> }
>> Cheers,
>> Carl
>> _______________________________________________
>> List: Catalyst at lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
> I don't want to work with an empty form. I want to get the form as created by
> formconfig and add some things to it. That's why I think subclassing is the
> way to go.

BTW, I'd be interested to know what you're trying to achieve.
Sub-classing Catalyst::Controller::HTML::FormFu::Action::FormConfig
won't allow you to intercept the form between it being populated with
the config-file, and $form->process() being called.
Although this often isn't an issue, you particularly don't want to
have to call process() twice if it's doing anything heavy-weight such
as calling DBIC or dealing with file uploads.

What I normally do is create a custom HTML::FormFu::Plugin::* class
with a process sub that does the necessary work.
It'll be called automatically during $form->process() before all the
input processing is done.

I've never yet considered having to sub-class C::C::HTML::FormFu or
any of its action classes.


More information about the Catalyst mailing list