Below is a full FormFu skeleton.

sub input_formfu : Local {
my ( $self, $c ) = @_;

# Create form object
my $form = $self->form;

# Load form configuration from a yaml file
$form->load_config_file('root/forms/data/input_formfu.yaml');

# Pass catalyst request object to form query method 
# Used only in POST phase.
$form->query( $c->req );

# Process the form - done in both GET/POST phases.
$form->process;

# Put the form in the stash for template rendering 
# Used in GET.
$c->stash->{form} = $form;

=head1 Form GET

Show the form.  
View falls through to default template if none specified. 
Default template = data/input_formfu.tt which in general is $controller_path/$action.tt
.tt is the extension becatse that has been chose as the default view type.

=cut

if ( !$form->submitted ) {



}
elsif ( $form->submitted_and_valid ) {
    $c->log->debug('Form Submitted and Valid');

    # Do something with the form data
    $c->response->body(
            'Form has been succesfully submitted.  I better do something with it.'
        );
    }

=head1 Form Errors

One of the reasons to use a form helper module such as FormFu is that
it will automatically show errors messages based on form constraints
setup in the configuration.  The constraints can be as simple as requiring
a non-empty input field or being more restrictive by specifying the data type
such as Integer, Word, Email etc.

=cut      

elsif ( $form->has_errors ) {
    $c->stash->{error_msg} = "Forms has errors";
    $c->log->debug('Form has Errors');
}
else {
    $c->log->debug('How the heck did I GET here');
}

return;
}

NOTE: This action (subroutine in Catalyst context) comes from a controller class called Data.pm

My tags:
 
Popular tags:
 
Powered by Catalyst
Powered by MojoMojo Hosted by Shadowcat - Managed by Nordaaker