3 Catalyst::Manual::Tutorial::09_AdvancedCRUD::09_FormSensible - Catalyst Tutorial - Chapter 9: Advanced CRUD - FormSensible
8 This is B<Chapter 9 of 10> for the Catalyst tutorial.
10 L<Tutorial Overview|Catalyst::Manual::Tutorial>
16 L<Introduction|Catalyst::Manual::Tutorial::01_Intro>
20 L<Catalyst Basics|Catalyst::Manual::Tutorial::02_CatalystBasics>
24 L<More Catalyst Basics|Catalyst::Manual::Tutorial::03_MoreCatalystBasics>
28 L<Basic CRUD|Catalyst::Manual::Tutorial::04_BasicCRUD>
32 L<Authentication|Catalyst::Manual::Tutorial::05_Authentication>
36 L<Authorization|Catalyst::Manual::Tutorial::06_Authorization>
40 L<Debugging|Catalyst::Manual::Tutorial::07_Debugging>
44 L<Testing|Catalyst::Manual::Tutorial::08_Testing>
48 B<09_Advanced CRUD::09_FormHandler>
52 L<Appendices|Catalyst::Manual::Tutorial::10_Appendices>
59 This part of the tutorial explores managing your CRUD operations with L<Form::Sensible> and L<Form::Sensible::Reflector::DBIC>.
60 As of this writing, Form::Sensible is at version 0.20002 and Form::Sensible::Reflector::DBIC is at 0.0341.
63 L<Catalyst::Manual::Tutorial::09_AdvancedCRUD|Catalyst::Manual::Tutorial::09_AdvancedCRUD>
64 for additional form management options other than L<Form::Sensible>.
66 =head1 Installing Form::Sensible
68 The easiest way to install L<Form::Sensible> is via CPAN:
74 cpan Form::Sensible::Reflector::DBIC
76 if you're using the reflector.
80 requires 'Form::Sensible';
84 requires 'Form::Sensible::Reflector::DBIC';
86 to your app's C<Makefile.PL>.
92 L<Form::Sensible Form Creation>
94 L<Form::Sensible::Reflector::DBIC Form Creation>
96 =head1 Form::Sensible Form Creation
98 From the documentation, we can see that you are able to create forms via simple data structures or programmatically.
99 Typically, it's easiest to the do former, so we'll use that example here:
103 my $form = Form::Sensible->create_form( {
107 field_class => 'Text',
109 validation => { regex => '^[0-9a-z]*' }
112 field_class => 'Text',
116 field_type => 'password'
121 field_class => 'Trigger',
127 =head1 Form::Sensible::Reflector::DBIC Form Creation
129 A reflector literally reflects off of a data source, whether it's configuration files, XML files, or in this case, a L<DBIx::Class> schema object.
131 The long and the short of this is that Form::Sensible::Reflector::DBIC searches through your schema and creates the appropriate form field types from the data types your columns are defined as.
133 All you need is your schema object from your model:
136 my $captcha = $c->captcha_string; # from Plugin::CAPTCHA
137 my $reflector = Form::Sensible::Reflector::DBIC->new;
138 my $form = $reflector->reflect_from( $c->model('Database::Quote'),
139 { form => { name => 'uploads' } } );
140 my $captcha_field = Form::Sensible::Field::Text->new(
142 default_value => $captcha,
145 my $submit_button = Form::Sensible::Field::Trigger->new( name => 'add' );
146 my $renderer = Form::Sensible->get_renderer('HTML');
148 $form->add_field($captcha_field);
149 $form->add_field($submit_button);
151 if ( $c->req->param('add') ) {
153 $c->forward(qw/Controller::API::Quote create/);
157 my $output = $renderer->render($form)->complete( '/quotes/new', 'POST' );
158 $c->stash( form => $output );