I've been attempting to use HTML::FormHandler with Catalyst following this tutorial:

http://search.cpan.org/dist/Catalyst-Manual/lib/Catalyst/Manual/Tutorial/09_AdvancedCRUD/09_FormHandler.pod

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:

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;
In my controller, I have:
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.


In reply to Trying to make HTML::FormHandler and Catalyst play nice together by LunarCowgirl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.