[html-formfu] Displaying 2 forms in the same page
Andreas Marienborg
omega at palle.net
Mon Oct 13 14:50:06 BST 2008
=head2 Multiple forms using Catalyst::Controller::HTML::FormFu
Sometimes you need to display multiple forms on a single page. If you
try to use FormConfig on several actions in a chain, or similar, they
all use $c->stash->{form} to store the form, hence you only get the last
form.
One way to work around such problems is to do a little of the work
yourself:
In this example we have a login_form that we want on every page
root/forms/login.yml:
---
elements:
-
type: Text
name: username
...
We load this in the top-most auto action:
package MyApp::Controller::Root;
use parent 'Catalyst::Controller::HTML::FormFu';
sub auto : Private {
my ($self, $c) = @_;
# We want to utilize alot of the magic that the controller
# gives us, so therefore we call $self->form like this
my $login_form = $self->form;
$login_form->load_config('forms/login.yml');
# Notice how we put it into another stash var, not 'form'
$c->stash->{login_form} = $login_form;
}
Any other page that wants to load another form, can now do so freely:
package MyApp::Controller::Foo;
sub edit : Local FormConfig {
}
Finaly, we need to show both forms:
root/foo/edit.tt
[% login_form %]
<h2>edit</h2>
[% form %]
Something like that?
If no-one objects, I'll commit it tomorrow
- andreas
On Oct 13, 2008, at 9:44 AM, Oleg Kostyuk wrote:
> Andreas, may be you lodged this as doc patch for
> HTML::FormFu::Manual::Cookbook and send it to Carl ?
>
> --
> Sincerely yours,
> Oleg Kostyuk (CUB-UANIC)
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
More information about the HTML-FormFu
mailing list