NAME
Catalyst::Controller::HTML::FormHandler
SYNOPSIS
A base controller class for Catalyst controllers to use HTML::FormHandler forms.
DESCRIPTION
In a Catalyst controller:
package MyApp::Controller::Book;
use base 'Catalyst::Controller::Form::Processor';
__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' }} );
Config Options
- model_name
-
Set the Catalyst model name. Currently only used by Form::Processor::Model::DBIC.
- 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 Form::Processor, 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
DESCRIPTION
The "end" method will use FillInForm to render the form, unless the "fif" config value has been set to false.
If you have a custom "end" routine in your subclassed controllers and want to use FillInForm to fill in your forms, you can use this as a sample of how to handle FillInForm in your custom 'end'.
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.
3 POD Errors
The following errors were encountered while parsing the POD:
- Around line 98:
You forgot a '=back' before '=head1'
- Around line 202:
You forgot a '=back' before '=head1'
- Around line 211:
=back without =over