I'm trying to use FormHandler within my Catalyst-application (also
using DBIC) - but I have some startup problems which I cannot solve
yet ... Hope anybody can give me some hints here:
What I have is a form, defined in a own package:
--START CODE---
package BDBInfo2::Form::Userinfo::Edit;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler::Model::DBIC';
with 'HTML::FormHandler::Render::Simple';
use namespace::autoclean;
has '+item_class' => ( default =>'Userinfo', );
has_field 'userinfo_kuerzel' => ( type => 'Text', label =>
'Userkuerzel' );
has_field 'fk_bdbrolle_pk' => ( type => 'Select', label => "Rolle",
label_column => 'bdbrolle_name');
has_field 'submit' => ( type => 'Submit', value => 'Uebernehmen');
has_field 'cancel' => ( type => 'Button', value => 'Abbrechen' );
---END CODE---
Now I try to use this within my catalyst controller:
--START CODE---
has 'edit_form' => ( isa => 'BDBInfo2::Form::Userinfo::Edit', is =>
'rw',
lazy => 1, default => sub { BDBInfo2::Form::Userinfo::Edit-
>new } );
...
sub edit :Chained("base") :PathPart("edit") :Args(1) {
my ( $self, $c, $arg1 ) = @_;
my $userinfo = $c->model('BDB::Userinfo')->find($arg1);
my $result = $self->edit_form->run( item => $userinfo, params => $c-
>req->parameters);
$c->stash( template => '
userinfo_edit.tt', form => $result );
if (!$result->validated) {
use Data::Dumper;
$c->log->debug( "------------------------------"));
$c->res->redirect( $c->uri_for('edit/'.$arg1) );
}
else {
$c->log->debug("+++++++++++++++++++++++++++"));
$c->res->redirect( $c->uri_for('edit/'.$arg1) );
}
return
}
---END CODE---
What currently happens is running an endless loop when calling the
"edit"-URI. I know this comes from my "redirect"-call, but I assumed
this happens only after validation - and validation should only be
performed (as I thought) after pressing the "submit" or "cancel"
button. This seems not be the case.
I don't understand where the form processing loop is done, waiting for
the event of "pressing a button"?
How is the "proper" code for processing the two possible events
"cancel" and "submit"? (I don't even know how to determine whether
"cancel" or "submit" button was pressed ...)
Any hints welcome - and excuse those obvious NOOB questions, but I
can't find a solution yet, unless I researched/tried/googled a lot ...
Hoppfrosch