NAME
Catalyst::Controller::Role::HTML::FormHandler - a Moose role for Catalyst controllers
SYNOPSIS
A Moose role for Catalyst controllers to use HTML::FormHandler forms.
DESCRIPTION
In a Catalyst controller:
package MyApp::Controller::Book;
use Moose ('with');
use base ('Catalyst::Controller', 'Moose::Object');
with 'Catalyst::Controller::Role::HTML::FormHandler';
__PACKAGE__->config( model_name => 'DB', form_name_space => 'MyApp::Form');
sub book_base : Chained PathPart('book') CaptureArgs(0)
{
my ( $self, $c ) = @_;
# setup
}
sub item : Chained('book_base') PathPart('') CaptureArgs(1)
{
my ( $self, $c, $book_id ) = @_;
$c->stash->{book} = $c->model('DB::Book')->find($book_id);
}
sub edit : Chained('item') PathPart('edit') Args(0)
{
my ( $self, $c ) = @_;
return $self->form($c);
}
sub form
{
my ( $self, $c ) = @_;
$self->ctx->stash->{template} = 'book/form.tt';
return unless $self->update_from_form( $c->stash->{book}, 'Book' );
$c->res->redirect( $c->uri_for('list') );
}
(See Catalyst::Controller::HTML::FormHandler for non-chained example.)
Or configure model_name and form_name_space for the entire app:
MyApp->config( { 'Controller::HTML::FormHandler' =>
{ model_name => 'DB', form_name_space => 'MyApp::Form' }} );
(Note that the config key does not use "Role".)
If you set the 'fif' attribute, the $form->fif
hash will be stored in $c->stash->{fillinform}
for you to pass to HTML::FillInForm
Config Options
- model_name
-
Set the Catalyst model name. Currently only used by HTML::FormHandler::Model::DBIC to set the schema.
- form_name_space
-
Set the name space to look for forms. Otherwise, forms will be found in a "Form" directory parallel to the controller directory. Override with "+" and complete package name.
- fif
-
Set
$c->stash->{fillinform}
to the$form->fif
parameter hash so you can use it to call FillInForm.
METHODS
- get_form
-
Determine the form package name, and "require" the form. Massage the parameters into the form expected by FormHandler, including getting the schema from the model name and passing it into the DBIC model. Put the form object into the Catalyst stash.
- validate_form
-
Validate the form
- update_from_form
-
Use for forms that have a database interface
- form_posted
-
convenience method checking for POST
AUTHOR
Gerda Shank, modeled on Catalyst::Plugin::Form::Processor by Bill Moseley
COPYRIGHT
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 119:
You forgot a '=back' before '=head1'
- Around line 227:
You forgot a '=back' before '=head1'