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 base 'Catalyst::Controller';
with 'Catalyst::Controller::Role::HTML::FormHandler';
__PACKAGE__->config( model_name => 'DB', form_name_space => 'MyApp::Form');
sub edit : Local {
my ( $self, $c ) = @_;
$c->forward('do_form');
}
sub form : Private {
my ( $self, $c, $id ) = @_;
# Name template, or allow default 'book/add.tt'
$self->ctx->stash->{template} = 'book/form.tt';
# Name form, or use default 'Book::Add'
my $validated = $self->update_from_form( $id, 'Book' );
return if !$validated; # This (re)displays the form, because it's the
# 'end' of the method, and the 'default end' action
# takes over, which is to render the view
# or simpler syntax: return unless $self->update_from_form( $id, 'Book');
# get the new book that was just created by the form
my $new_book = $c->stash->{form}->item;
$c->res->redirect($c->uri_for('list'));
}
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".)
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.
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 106:
You forgot a '=back' before '=head1'
- Around line 215:
You forgot a '=back' before '=head1'