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

Carl Franks fireartist at gmail.com
Sat Jan 17 21:11: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.

In that case, sub-classing Catalyst::Controller::HTML::FormFu won't help.
You need to create a sub-class of
Catalyst::Controller::HTML::FormFu::Action::FormConfig
and then set your app's config to use your class to handle FormConfig()

myapp.yml
---------

'Controller::HTML::FormFu':
  config_action: 'Classname::Of::Your::Custom::SubClass'



More information about the Catalyst mailing list