This software is a framework that allows for the creation, rendering, and validation of HTML forms. It helps streamline the process of building forms and ensures that they are error-free and responsive.
To use HTML::FormFu, one can load the module and create a new form object. This example makes use of the HTML::FormFu::Model::DBIC module, which is now available in a stand-alone distribution:
use HTML::FormFu;
my $form = HTML::FormFu->new;
$form->load_config_file('form.yml');
$form->process($cgi_query);
If the form is submitted and valid, the form data can be processed as desired. Otherwise, the form can be displayed again for the user to fill out.
For those using HTML::FormFu with Catalyst, the code looks a bit different:
package MyApp::Controller::User;
use strict;
use base 'Catalyst::Controller::HTML::FormFu';
sub user : Chained CaptureArgs(1) {
my ( $self, $c, $id ) = @_;
my $rs = $c->model('Schema')->resultset('User');
$c->stash->{user} = $rs->find( $id );
return;
}
sub edit : Chained('user') Args(0) FormConfig {
my ( $self, $c ) = @_;
my $form = $c->stash->{form};
my $user = $c->stash->{user};
if ( $form->submitted_and_valid ) {
$form->model->update( $user );
$c->res->redirect( $c->uri_for( "/user/$id" ) );
return;
}
$form->model->default_values( $user )
if ! $form->submitted;
}
Note that because "process" is automatically called by the Catalyst controller, any modifications made to the form within the action method must be followed by a call to "process" before performing other actions.
HTML::FormFu can be configured using a YAML or other Config::Any file. The following example creates a basic login form with required fields:
---
action: /login
indicator: submit
auto_fieldset: 1
elements:
- type: Text
name: user
constraints:
- Required
- type: Password
name: pass
constraints:
- Required
- type: Submit
name: submit
constraints:
- SingleValue
Overall, HTML::FormFu is designed to be easy to use for basic web forms while offering flexibility for more complicated tasks. The default output is XHTML 1.0 Strict-compliant markup with minimal extra markup, allowing for custom styling via CSS class names. All methods for using HTML::FormFu (except "new") can be called as a method or configuration option, following the convention that square-bracketed arguments are optional.
Version 0.05000: N/A