LunarCowgirl has asked for the wisdom of the Perl Monks concerning the following question:
I've been attempting to use HTML::FormHandler with Catalyst following this tutorial:
which is similar to this one here:
https://metacpan.org/pod/Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormHandler
and also looking at these:
http://search.cpan.org/~gshank/HTML-FormHandler-0.40057/lib/HTML/FormHandler/Manual/Tutorial.pod http://search.cpan.org/~gshank/HTML-FormHandler-0.40057/lib/HTML/FormHandler/Manual/Catalyst.pod
I've started a basic form for editing a database entry and can get the form to render, but I can't manage to make it display data.
My form class:
In my controller, I have:package MyApp::Form::Book; use utf8; use HTML::FormHandler::Moose; extends 'HTML::FormHandler::Model::DBIC'; use namespace::autoclean; has '+item_class' => ( default => 'Book' ); has_field 'title' => ( type => 'Text', required => 1, label => 'Title', ); has_field 'comment' => ( type => 'Text', required => 1, ); __PACKAGE__->meta->make_immutable; 1;
sub edit_book : Local : Args(1) { my ( $self, $c, $id ) = @_; my $book = $c->model('DB::Book')->find($id); return $self->form($c, $book); } sub form : Private { my ( $self, $c, $book ) = @_; my $form = MyApp::Form::Book->new; $c->stash( template => 'admin/edit_book.tt', title => 'Edit Book', form => $form, ); $form->process->( item => $book, params => $c->req->params ); return unless $form->validated; }
This is pretty much exactly as it is in the tutorial, even down to the fact that I'm working with a book table, however the $form->process line returns an exception when I try to render the page: Can't use string "" as an array ref while 'strict refs' in use. Commenting out that line allows a blank form to render.
I know that $book is a valid object because I can pass it into stash and display its title through Template Toolkit. I'm not sure why it's causing that error. The tutorial is slim on words, mostly saying "do this" without explaining what you're doing or why you're doing it, and the HTML::FormHandler docs haven't enlightened me much beyond that either. What am I missing?
One thing I may not be clear on is what to put as "default" for "+item_class" in the form package. The docs say "the source name of your DBIx::Class result class," which I'm assuming is the name of the MyApp::Schema::Result or ResultSet class, which would be "Book" in my case. One thing I've learned since I've started working with Catalyst though is that assumptions are often wrong.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to make HTML::FormHandler and Catalyst play nice together
by LunarCowgirl (Sexton) on Sep 11, 2014 at 16:45 UTC |