.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Catalyst::Controller::HTML::FormFu 3pm" .TH Catalyst::Controller::HTML::FormFu 3pm "2018-05-15" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catalyst::Controller::HTML::FormFu \- Catalyst integration for HTML::FormFu .SH "VERSION" .IX Header "VERSION" version 2.04 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package MyApp::Controller::My::Controller; \& \& use Moose; \& use namespace::autoclean; \& \& BEGIN { extends \*(AqCatalyst::Controller::HTML::FormFu\*(Aq; } \& \& sub index : Local { \& my ( $self, $c ) = @_; \& \& # doesn\*(Aqt use an Attribute to make a form \& # can get an empty form from $self\->form() \& \& my $form = $self\->form(); \& } \& \& sub foo : Local : Form { \& my ( $self, $c ) = @_; \& \& # using the Form attribute is equivalent to: \& # \& # my $form = $self\->form; \& # \& # $form\->process; \& # \& # $c\->stash\->{form} = $form; \& } \& \& sub bar : Local : FormConfig { \& my ( $self, $c ) = @_; \& \& # using the FormConfig attribute is equivalent to: \& # \& # my $form = $self\->form; \& # \& # $form\->load_config_filestem(\*(Aqroot/forms/my/controller/bar\*(Aq); \& # \& # $form\->process; \& # \& # $c\->stash\->{form} = $form; \& # \& # so you only need to do the following... \& \& my $form = $c\->stash\->{form}; \& \& if ( $form\->submitted_and_valid ) { \& do_something(); \& } \& } \& \& sub baz : Local : FormConfig(\*(Aqmy_config\*(Aq) { \& my ( $self, $c ) = @_; \& \& # using the FormConfig attribute with an argument is equivalent to: \& # \& # my $form = $self\->form; \& # \& # $form\->load_config_filestem(\*(Aqroot/forms/my_config\*(Aq); \& # \& # $form\->process; \& # \& # $c\->stash\->{form} = $form; \& # \& # so you only need to do the following... \& \& my $form = $c\->stash\->{form}; \& \& if ( $form\->submitted_and_valid ) { \& do_something(); \& } \& } \& \& sub quux : Local : FormMethod(\*(Aqload_form\*(Aq) { \& my ( $self, $c ) = @_; \& \& # using the FormMethod attribute with an argument is equivalent to: \& # \& # my $form = $self\->form; \& # \& # $form\->populate( $c\->load_form ); \& # \& # $form\->process; \& # \& # $c\->stash\->{form} = $form; \& # \& # so you only need to do the following... \& \& my $form = $c\->stash\->{form}; \& \& if ( $form\->submitted_and_valid ) { \& do_something(); \& } \& } \& \& sub load_form { \& my ( $self, $c ) = @_; \& \& # Automatically called by the above FormMethod(\*(Aqload_form\*(Aq) action. \& # Called as a method on the controller object, with the context \& # object as an argument. \& \& # Must return a hash\-ref suitable to be fed to $form\->populate() \& } .Ve .PP You can also use specially-named actions that will only be called under certain circumstances. .PP .Vb 1 \& sub edit : Chained(\*(Aqgroup\*(Aq) : PathPart : Args(0) : FormConfig { } \& \& sub edit_FORM_VALID { \& my ( $self, $c ) = @_; \& \& my $form = $c\->stash\->{form}; \& my $group = $c\->stash\->{group}; \& \& $form\->model\->update( $group ); \& \& $c\->response\->redirect( $c\->uri_for( \*(Aq/group\*(Aq, $group\->id ) ); \& } \& \& sub edit_FORM_NOT_SUBMITTED { \& my ( $self, $c ) = @_; \& \& my $form = $c\->stash\->{form}; \& my $group = $c\->stash\->{group}; \& \& $form\->model\->default_values( $group ); \& } .Ve .SH "METHODS" .IX Header "METHODS" .SS "form" .IX Subsection "form" This creates a new HTML::FormFu object, passing as it's argument the contents of the \*(L"constructor\*(R" config value. .PP This is useful when using the \fIConfigForm()\fR or \fIMethodForm()\fR action attributes, to create a 2nd form which isn't populated using a config-file or method return value. .PP .Vb 2 \& sub foo : Local { \& my ( $self, $c ) = @_; \& \& my $form = $self\->form; \& } .Ve .PP Note that when using this method, the form's query method is not populated with the Catalyst request object. .SH "SPECIAL ACTION NAMES" .IX Header "SPECIAL ACTION NAMES" An example showing how a complicated action method can be broken down into smaller sections, making it clearer which code will be run, and when. .PP .Vb 2 \& sub edit : Local : FormConfig { \& my ( $self, $c ) = @_; \& \& my $form = $c\->stash\->{form}; \& my $group = $c\->stash\->{group}; \& \& $c\->detach(\*(Aq/unauthorised\*(Aq) unless $c\->user\->can_edit( $group ); \& \& if ( $form\->submitted_and_valid ) { \& $form\->model\->update( $group ); \& \& $c\->response\->redirect( $c\->uri_for(\*(Aq/group\*(Aq, $group\->id ) ); \& return; \& } \& elsif ( !$form\->submitted ) { \& $form\->model\->default_values( $group ); \& } \& \& $self\->_add_breadcrumbs_nav( $c, $group ); \& } .Ve .PP Instead becomes... .PP .Vb 2 \& sub edit : Local : FormConfig { \& my ( $self, $c ) = @_; \& \& $c\->detach(\*(Aq/unauthorised\*(Aq) unless $c\->user\->can_edit( \& $c\->stash\->{group} \& ); \& } \& \& sub edit_FORM_VALID { \& my ( $self, $c ) = @_; \& \& my $group = $c\->stash\->{group}; \& \& $c\->stash\->{form}\->model\->update( $group ); \& \& $c\->response\->redirect( $c\->uri_for(\*(Aq/group\*(Aq, $group\->id ) ); \& } \& \& sub edit_FORM_NOT_SUBMITTED { \& my ( $self, $c ) = @_; \& \& $c\->stash\->{form}\->model\->default_values( \& $c\->stash\->{group} \& ); \& } \& \& sub edit_FORM_RENDER { \& my ( $self, $c ) = @_; \& \& $self\->_add_breadcrumbs_nav( $c, $c\->stash\->{group} ); \& } .Ve .PP For any action method that uses a \f(CW\*(C`Form\*(C'\fR, \f(CW\*(C`FormConfig\*(C'\fR or \f(CW\*(C`FormMethod\*(C'\fR attribute, you can add extra methods that use the naming conventions below. .PP These methods will be called after the original, plainly named action method. .SS "_FORM_VALID" .IX Subsection "_FORM_VALID" Run when the form has been submitted and has no errors. .SS "_FORM_SUBMITTED" .IX Subsection "_FORM_SUBMITTED" Run when the form has been submitted, regardless of whether or not there was errors. .SS "_FORM_COMPLETE" .IX Subsection "_FORM_COMPLETE" For MultiForms, is run if the MultiForm is completed. .SS "_FORM_NOT_VALID" .IX Subsection "_FORM_NOT_VALID" Run when the form has been submitted and there were errors. .SS "_FORM_NOT_SUBMITTED" .IX Subsection "_FORM_NOT_SUBMITTED" Run when the form has not been submitted. .SS "_FORM_NOT_COMPLETE" .IX Subsection "_FORM_NOT_COMPLETE" For MultiForms, is run if the MultiForm is not completed. .SS "_FORM_RENDER" .IX Subsection "_FORM_RENDER" For normal \f(CW\*(C`Form\*(C'\fR base classes, this subroutine is run after any of the other special methods, unless \f(CW\*(C`$form\->submitted_and_valid\*(C'\fR is true. .PP For \f(CW\*(C`MultiForm\*(C'\fR base classes, this subroutine is run after any of the other special methods, unless \f(CW\*(C`$multi\->complete\*(C'\fR is true. .SH "CUSTOMIZATION" .IX Header "CUSTOMIZATION" You can set your own config settings, using either your controller config or your application config. .PP .Vb 1 \& $c\->config( \*(AqController::HTML::FormFu\*(Aq => \e%my_values ); \& \& # or \& \& MyApp\->config( \*(AqController::HTML::FormFu\*(Aq => \e%my_values ); \& \& # or, in myapp.conf \& \& \& default_action_use_path 1 \& .Ve .SS "form_method" .IX Subsection "form_method" Override the method-name used to create a new form object. .PP See \*(L"form\*(R". .PP Default value: \f(CW\*(C`form\*(C'\fR. .SS "form_stash" .IX Subsection "form_stash" Sets the stash key name used to store the form object. .PP Default value: \f(CW\*(C`form\*(C'\fR. .SS "form_attr" .IX Subsection "form_attr" Sets the attribute name used to load the Catalyst::Controller::HTML::FormFu::Action::Form action. .PP Default value: \f(CW\*(C`Form\*(C'\fR. .SS "config_attr" .IX Subsection "config_attr" Sets the attribute name used to load the Catalyst::Controller::HTML::FormFu::Action::Config action. .PP Default value: \f(CW\*(C`FormConfig\*(C'\fR. .SS "method_attr" .IX Subsection "method_attr" Sets the attribute name used to load the Catalyst::Controller::HTML::FormFu::Action::Method action. .PP Default value: \f(CW\*(C`FormMethod\*(C'\fR. .SS "form_action" .IX Subsection "form_action" Sets which package will be used by the \fIForm()\fR action. .PP Probably only useful if you want to create a sub-class which provides custom behaviour. .PP Default value: \f(CW\*(C`Catalyst::Controller::HTML::FormFu::Action::Form\*(C'\fR. .SS "config_action" .IX Subsection "config_action" Sets which package will be used by the \fIConfig()\fR action. .PP Probably only useful if you want to create a sub-class which provides custom behaviour. .PP Default value: \f(CW\*(C`Catalyst::Controller::HTML::FormFu::Action::Config\*(C'\fR. .SS "method_action" .IX Subsection "method_action" Sets which package will be used by the \fIMethod()\fR action. .PP Probably only useful if you want to create a sub-class which provides custom behaviour. .PP Default value: \f(CW\*(C`Catalyst::Controller::HTML::FormFu::Action::Method\*(C'\fR. .SS "constructor" .IX Subsection "constructor" Pass common defaults to the HTML::FormFu constructor. .PP These values are used by all of the action attributes, and by the \f(CW\*(C`$self\->form\*(C'\fR method. .PP Default value: \f(CW\*(C`{}\*(C'\fR. .SS "config_callback" .IX Subsection "config_callback" Arguments: bool .PP If true, a coderef is passed to \f(CW\*(C`$form\->config_callback\->{plain_value}\*(C'\fR which replaces any instance of \f(CW\*(C`_\|_uri_for(URI)_\|_\*(C'\fR found in form config files with the result of passing the \f(CW\*(C`URI\*(C'\fR argument to \*(L"uri_for\*(R" in Catalyst. .PP The form \f(CW\*(C`_\|_uri_for(URI, PATH, PARTS)_\|_\*(C'\fR is also supported, which is equivalent to \f(CW\*(C`$c\->uri_for( \*(AqURI\*(Aq, \e@ARGS )\*(C'\fR. At this time, there is no way to pass query values equivalent to \f(CW\*(C`$c\->uri_for( \*(AqURI\*(Aq, \e@ARGS, \&\e%QUERY_VALUES )\*(C'\fR. .PP The second codeword that is being replaced is \f(CW\*(C`_\|_path_to( @DIRS )_\|_\*(C'\fR. Any instance is replaced with the result of passing the \f(CW\*(C`DIRS\*(C'\fR arguments to \&\*(L"path_to\*(R" in Catalyst. Don't use qoutationmarks as they would become part of the path. .PP Default value: 1 .SS "default_action_use_name" .IX Subsection "default_action_use_name" If set to a true value the action for the form will be set to the currently called action name. .PP Default value: \f(CW\*(C`false\*(C'\fR. .SS "default_action_use_path" .IX Subsection "default_action_use_path" If set to a true value the action for the form will be set to the currently called action path. The action path includes concurrent to action name additioal parameters which were code inside the path. .PP Default value: \f(CW\*(C`false\*(C'\fR. .PP Example: .PP .Vb 2 \& action: /foo/bar \& called uri contains: /foo/bar/1 \& \& # default_action_use_name => 1 leads to: \& $form\->action = /foo/bar \& \& # default_action_use_path => 1 leads to: \& $form\->action = /foo/bar/1 .Ve .SS "model_stash" .IX Subsection "model_stash" Arguments: \e%stash_keys_to_model_names .PP Used to place Catalyst models on the form stash. .PP If it's being used to make a DBIx::Class schema available for \&\*(L"options_from_model\*(R" in HTML::FormFu::Model::DBIC, for \f(CW\*(C`Select\*(C'\fR and other Group-type elements \- then the hash-key must be \f(CW\*(C`schema\*(C'\fR. For example, if your schema model class is \f(CW\*(C`MyApp::Model::MySchema\*(C'\fR, you would set \f(CW\*(C`model_stash\*(C'\fR like so: .PP .Vb 5 \& \& \& schema MySchema \& \& .Ve .SS "context_stash" .IX Subsection "context_stash" To allow your form validation packages, etc, access to the catalyst context, a weakened reference of the context is copied into the form's stash. .PP .Vb 1 \& $form\->stash\->{context}; .Ve .PP This setting allows you to change the key name used in the form stash. .PP Default value: \f(CW\*(C`context\*(C'\fR .SS "languages_from_context" .IX Subsection "languages_from_context" If you're using a L10N / I18N plugin such as Catalyst::Plugin::I18N which provides a \f(CW\*(C`languages\*(C'\fR method that returns a list of valid languages to use for the currect request \- and you want to use formfu's built-in I18N packages, then setting \*(L"languages_from_context\*(R" .SS "localize_from_context" .IX Subsection "localize_from_context" If you're using a L10N / I18N plugin such as Catalyst::Plugin::I18N which provides it's own \f(CW\*(C`localize\*(C'\fR method, you can set localize_from_context to use that method for formfu's localization. .SS "request_token_enable" .IX Subsection "request_token_enable" If true, adds an instance of HTML::FormFu::Plugin::RequestToken to every form, to stop accidental double-submissions of data and to prevent \s-1CSRF\s0 attacks. .SS "request_token_field_name" .IX Subsection "request_token_field_name" Defaults to \f(CW\*(C`_token\*(C'\fR. .SS "request_token_session_key" .IX Subsection "request_token_session_key" Defaults to \f(CW\*(C`_\|_token\*(C'\fR. .SS "request_token_expiration_time" .IX Subsection "request_token_expiration_time" Defaults to \f(CW3600\fR. .SH "DISCONTINUED CONFIG SETTINGS" .IX Header "DISCONTINUED CONFIG SETTINGS" .SS "config_file_ext" .IX Subsection "config_file_ext" Support for this has now been removed. Config files are now searched for, with any file extension supported by Config::Any. .SS "config_file_path" .IX Subsection "config_file_path" Support for this has now been removed. Use \f(CW\*(C`{constructor}{config_file_path}\*(C'\fR instead. .SH "CAVEATS" .IX Header "CAVEATS" When using the \f(CW\*(C`Form\*(C'\fR action attribute to create an empty form, you must call \&\f(CW$form\fR\->process after populating the form. However, you don't need to pass any arguments to \f(CW\*(C`process\*(C'\fR, as the Catalyst request object will have automatically been set in \f(CW$form\fR\->query. .PP When using the \f(CW\*(C`FormConfig\*(C'\fR and \f(CW\*(C`FormMethod\*(C'\fR action attributes, if you make any modifications to the form, such as adding or changing it's elements, you must call \f(CW$form\fR\->process before rendering the form. .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Carl Franks .IP "\(bu" 4 Nigel Metheringham .IP "\(bu" 4 Dean Hamstead .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2007\-2018 by Carl Franks / Nigel Metheringham / Dean Hamstead. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "SUPPORT" .IX Header "SUPPORT" .SS "Perldoc" .IX Subsection "Perldoc" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc Catalyst::Controller::HTML::FormFu .Ve .SS "Websites" .IX Subsection "Websites" The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources. .IP "\(bu" 4 MetaCPAN .Sp A modern, open-source \s-1CPAN\s0 search engine, useful to view \s-1POD\s0 in \s-1HTML\s0 format. .Sp .IP "\(bu" 4 Search \s-1CPAN\s0 .Sp The default \s-1CPAN\s0 search engine, useful to view \s-1POD\s0 in \s-1HTML\s0 format. .Sp .IP "\(bu" 4 \&\s-1RT: CPAN\s0's Bug Tracker .Sp The \s-1RT\s0 ( Request Tracker ) website is the default bug/issue tracking system for \s-1CPAN.\s0 .Sp .IP "\(bu" 4 AnnoCPAN .Sp The AnnoCPAN is a website that allows community annotations of Perl module documentation. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Ratings .Sp The \s-1CPAN\s0 Ratings is a website that allows community ratings and reviews of Perl modules. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Forum .Sp The \s-1CPAN\s0 Forum is a web forum for discussing Perl modules. .Sp .IP "\(bu" 4 \&\s-1CPANTS\s0 .Sp The \s-1CPANTS\s0 is a website that analyzes the Kwalitee ( code metrics ) of a distribution. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers .Sp The \s-1CPAN\s0 Testers is a network of smokers who run automated tests on uploaded \s-1CPAN\s0 distributions. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers Matrix .Sp The \s-1CPAN\s0 Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms. .Sp .IP "\(bu" 4 \&\s-1CPAN\s0 Testers Dependencies .Sp The \s-1CPAN\s0 Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution. .Sp .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests by email to \f(CW\*(C`bug\-catalyst\-controller\-html\-formfu at rt.cpan.org\*(C'\fR, or through the web interface at . You will be automatically notified of any progress on the request by the system. .SS "Source Code" .IX Subsection "Source Code" The code is open to the world, and available for you to hack on. Please feel free to browse it and play with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull from your repository :) .PP .PP .Vb 1 \& git clone https://github.com/FormFu/Catalyst\-Controller\-HTML\-FormFu.git .Ve .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Aran Deltac .IP "\(bu" 4 bricas .IP "\(bu" 4 dandv .IP "\(bu" 4 fireartist .IP "\(bu" 4 lestrrat .IP "\(bu" 4 marcusramberg .IP "\(bu" 4 mariominati .IP "\(bu" 4 Moritz Onken <1nd@gmx.de> .IP "\(bu" 4 Moritz Onken .IP "\(bu" 4 Nigel Metheringham .IP "\(bu" 4 omega .IP "\(bu" 4 Petr Písař