[Catalyst] More than one form per page with C::C::FormBuilder?
Danny Warren
danny at io.com
Mon Feb 12 01:50:53 GMT 2007
Hey all!
I am trying to figure out the most elegant way to build/include multiple
forms in one page using Catalyst::Controller::FormBuilder.
Right now I am doing it as follows...
In my controller:
sub foo : Local Form
{
my ( $self, $c ) = @_;
# Form that actually belongs to "foo"
my $form = $self->formbuilder;
# Form for the search bar, belongs to "foo_search"
my $search_form = $c->forward('foo_search');
}
sub foo_search : Local Form
{
my ( $self, $c ) = @_;
# Form that belongs to "foo_search"
my $form = $self->formbuilder;
# Return the search form
return $form;
}
In the "foo.tt" template:
<!-- Should be the "foo_search" form -->
[% INCLUDE foo_search.tt %]
<!-- Should render the "foo" form -->
[% FormBuilder.render %]
In the foo_search.tt template:
<!-- Should render the "foo_search" form -->
[% FormBuilder.render %]
What I end up with when viewing the "foo" action page is two
"foo_search" forms. I understand why this happening, from an internals
standpoint, but I am not sure how to get around it without ugly hacking.
I would like to be able to keep the niceness of the "Form" pragma in
the controller and all the cool things that go along with it.
Has anyone found a good way to do this? What about if I wanted to build
two different forms from within one page directly in the action (not
using forwards)?
Is the general rule of thumb to only use the "Form" pragma if there will
only be one form, and use FormBuilder directly (so I can choose a unique
variable namespace for each) if there will be multiple?
Thanks!
Danny
More information about the Catalyst
mailing list