Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormHandler - Catalyst Tutorial - Chapter 9: Advanced CRUD - FormHandler
-
=head1 OVERVIEW
This is B<Chapter 9 of 10> for the Catalyst tutorial.
requires 'HTML::FormHandler::Model::DBIC';
-to your C<Makefile.PL>.
+to your F<Makefile.PL>.
=head1 HTML::FormHandler FORM CREATION
=head2 Create a Book Form
-Create the directory C<lib/MyApp/Form>. Create C<lib/MyApp/Form/Book.pm>:
+Create the directory F<lib/MyApp/Form>. Create F<lib/MyApp/Form/Book.pm>:
package MyApp::Form::Book;
=head2 Add Action to Display and Save the Form
-At the top of the C<lib/MyApp/Controller/Books.pm> add:
+At the top of the F<lib/MyApp/Controller/Books.pm> add:
use MyApp::Form::Book;
=head2 Create a Template Page To Display The Form
-Open C<root/src/books/form.tt2> in your editor and enter the following:
+Open F<root/src/books/form.tt2> in your editor and enter the following:
[% META title = 'Create/Update Book' %]
=head2 Add Link for Create
-Open C<root/src/books/list.tt2> in your editor and add the following to
+Open F<root/src/books/list.tt2> in your editor and add the following to
the bottom of the existing file:
...
<p>
- HTML::FormHandler:
- <a href="[% c.uri_for(c.controller.action_for('create')) %]">Create</a>
+ HTML::FormHandler:
+ <a href="[% c.uri_for(c.controller.action_for('create')) %]">Create</a>
</p>
This adds a new link to the bottom of the book list page that we can
=head2 Add Constraints
-Open C<lib/MyApp/Form/Book.pm> in your editor.
+Open F<lib/MyApp/Form/Book.pm> in your editor.
Restrict the title size and make it required:
=head2 Create the 'edit' method
-Edit C<lib/MyApp/Controller/Books.pm> and add the following method:
+Edit F<lib/MyApp/Controller/Books.pm> and add the following method:
=head2 edit
return $self->form($c, $c->stash->{object});
}
-Update the C<root/src/books/list.tt2>, adding an 'edit' link below the
+Update the F<root/src/books/list.tt2>, adding an 'edit' link below the
"Delete" link to use the FormHandler edit method:
<td>
- [% # Add a link to delete a book %]
- <a href="[% c.uri_for(c.controller.action_for('delete'), [book.id]) %]">Delete</a>
- [% # Add a link to edit a book %]
- <a href="[% c.uri_for(c.controller.action_for('edit'), [book.id]) %]">Edit</a>
+ [% # Add a link to delete a book %]
+ <a href="[% c.uri_for(c.controller.action_for('delete'), [book.id]) %]">Delete</a>
+ [% # Add a link to edit a book %]
+ <a href="[% c.uri_for(c.controller.action_for('edit'), [book.id]) %]">Edit</a>
</td>