Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

After 08...

  • Loading branch information...
commit 36bcaaab8d77a0dfe419c26dc69347c03567ac25 1 parent f30696b
gerda.shank@gmail.com authored
View
7 Changes
@@ -1,4 +1,9 @@
-Revision history for Perl extension HTML::FormHandler
+Revision history for HTML::FormHandler
+
+0.08 Sun Jan 25 2009, 03:00
+ Remove controller and role. Refactor to support persistent
+ forms. Remove update_from_form method. Add 'process', and
+ 'update' methods. Update documentation to match. Update tutorial.
0.07 Thurs Jan 22 2009, 04:00
Add prereq of DateTime. Minor doc changes.
View
2  README
@@ -30,8 +30,6 @@ perldoc command.
perldoc HTML::FormHandler
perldoc HTML::FormHandler::Model::DBIC
perldoc HTML::FormHandler::Field
- perldoc Catalyst::Controller::HTML::FormHandler
- perldoc Catalyst::Controller::Role::HTML::FormHandler
COPYRIGHT AND LICENCE
View
5 lib/HTML/FormHandler.pm
@@ -18,6 +18,9 @@ HTML::FormHandler - form handler written in Moose
=head1 SYNOPSIS
+This package should currently be considered unstable since I am actively making
+changes and improvements.
+
HTML::FormHandler is based on L<Form::Processor>. The original goal was just
to make a Moose version of Form::Processor, but there were issues in maintaining
compatibility between the non-Moose and Moose versions. Although very similar to
@@ -864,6 +867,8 @@ attribute.
sub init_from_object
{
my $self = shift;
+
+ $self->item( $self->build_item ) if $self->item_id && !$self->item;
my $item = $self->init_object || $self->item || return;
for my $field ( $self->fields )
View
8 lib/HTML/FormHandler/Manual/Reference.pod
@@ -8,10 +8,8 @@ This is a concise reference of HTML::FormHandler.
HTML::FormHandler has a lot of options and many ways to customize your forms.
More complete documentation can be found at L<HTML::FormHandler>,
-L<HTML::FormHandler::Field>, L<HTML::FormHandler::Model::CDBI>,
-L<HTML::FormHandler::Model::DBIC>, L<HTML::FormHandler::Render::Simple>,
-L<Catalyst::Controller::Role::HTML::FormHandler>,
-and in the individual field classes.
+L<HTML::FormHandler::Field>, L<HTML::FormHandler::Model::DBIC>,
+L<HTML::FormHandler::Render::Simple>, and in the individual field classes.
=head1 Fields
@@ -136,7 +134,7 @@ These attributes are usually accessed in a subroutine or in a template.
=head2 Methods to subclass from HTML::FormHandler::Model::DBIC
- model_validate Add additional database type validation
+ validate_model Add additional database type validation
update_model To add additional actions on update
guess_field_type To create better field type assignment for auto forms
View
39 lib/HTML/FormHandler/Manual/Tutorial.pod
@@ -20,7 +20,7 @@ Use CPAN to install L<HTML::FormHandler>
We'll use the files that were created in the L<Catalyst::Tutorial>, in
order to concentrate on just the bits where HTML::FormHandler is useful.
You can download a tar file of the tutorial files from the Catalyst
-code repository. Check on L<Catalyst::Tutorial> for links.
+code repository. (See L<Catalyst::Manual::Tutorial::Intro>.)
=head2 Create an HTML::FormHandler form
@@ -49,9 +49,8 @@ create the file Book.pm.
This is your Form class. The form initializes the 'item_class' to the
source name of your DBIx::Class result class. The form's fields are defined
-in the 'profile' attribute. The names of the fields should match an
-accessor in your DBIx::Class result source: a column, relationship, or
-other accessor.
+in the 'profile' attribute. The names of the fields should match
+a column, relationship, or other accessor in your DBIx::Class result class.
The basic fields have only a 'type', such as
'Text', or 'Integer'. These types are actually the names of
@@ -69,10 +68,11 @@ this simple form the default types are adequate.
=head2 Connect HTML::FormHandler to your controller
-Your controller must use Moose:
+Edit lib/MyApp/Controller/Books.pm. Add use Moose:
use Moose;
use base 'Catalyst::Controller';
+ use MyApp::Form::Book;
Create an attribute to hold your form:
@@ -87,10 +87,12 @@ In C<lib/MyApp/Controller/Books.pm> add the following method:
sub edit : Local {
my ( $self, $c, $book_id ) = @_;
- $c->stash( template => 'books/edit.tt2' );
+ $c->stash( template => 'books/edit.tt2',
+ form => $self->form );
# Validate and insert/update database
return unless $self->form->process( item_id => $book_id,
+ params => $c->req->parameters,
schema => $c->model('DB::Books')->schema );
# Form validated, return to the books list
@@ -132,13 +134,13 @@ Open C<root/src/books/edit.tt2> in your editor and enter or copy the following:
<p>
[% f = form.field('title') %]
<label class="label" for="[% f.name %]">[% f.label %]:</label>
- <input type="text" name="[% f.name %]" id="[% f.name %]">[% f.fif %]
+ <input type="text" name="[% f.name %]" id="[% f.name %]" value="[% f.fif %]">
</p>
<p>
[% f = form.field('rating') %]
<label class="label" for="[% f.name %]">[% f.label %]:</label>
- <input type="text" name="[% f.name %]" id="[% f.name %]" %]>[% f.fif %]
+ <input type="text" name="[% f.name %]" id="[% f.name %]" %] value="[% f.fif %]">
</p>
<p>
@@ -147,7 +149,7 @@ Open C<root/src/books/edit.tt2> in your editor and enter or copy the following:
<select name="[% f.name %]" multiple="multiple" size="[% f.size %]">
[% FOR option IN f.options %]
<option value="[% option.value %]"
- [% FOREACH selval IN f.value %]
+ [% FOREACH selval IN f.fif %]
[% IF selval == option.value %]selected="selected"[% END %]
[% END %]>
[% option.label | html %]</option>
@@ -211,16 +213,15 @@ keys and values:
fields => {
title => {
type => 'Text',
- label => 'Title',
+ label => 'Title of Book',
},
rating => {
type => 'Integer',
- label => 'Rating',
+ label => 'Rating (1-5)',
},
authors => {
type => 'Multiple',
label_column => 'last_name',
- label => 'Authors',
},
}
}
@@ -269,7 +270,7 @@ Update the 'profile' subroutine in your MyApp::Form::Book file:
fields => {
title => {
type => 'Text',
- label => 'Title',
+ label => 'Title of Book',
required => 1,
size => 40,
min_length => 5,
@@ -278,6 +279,7 @@ Update the 'profile' subroutine in your MyApp::Form::Book file:
type => 'Integer',
label => 'Rating',
required => 1,
+ required_message => 'You must rate the book',
range_start => 1,
range_end => 5,
},
@@ -285,7 +287,6 @@ Update the 'profile' subroutine in your MyApp::Form::Book file:
type => 'Multiple',
label_column => 'last_name',
required => 1,
- label => 'Author',
},
}
}
@@ -320,7 +321,7 @@ MyApp::Form::Book:
}
You can also have a 'cross_validation' routine to check interdependencies.
-The 'model_validate' routine is the place to perform database specific validation.
+The 'validate_model' routine is the place to perform database specific validation.
You can validate that the field is unique, or use a dependency list to make
more fields required if one is updated.
@@ -342,14 +343,6 @@ L<DBIx::Class> classes. L<HTML::FormHandler::Model::DBIC> allows
the use of custom accessors, making it easier to keep the code
in the right place.
-
-=head2 If you're addicted to YAML
-
-If you really, really want to define your form fields in YAML, you
-could use Config::Any to load the field definitions from a YAML (or
-other config file format) file and return them in the 'profile' subroutine.
-This could easily be automated in a Form base class.
-
=head1 AUTHORS
Gerda Shank, gshank@cpan.org
View
6 lib/HTML/FormHandler/Model/CDBI.pm
@@ -5,7 +5,7 @@ use Carp;
use Data::Dumper;
extends 'HTML::FormHandler';
-our $VERSION = '0.01';
+our $VERSION = '0.02';
=head1 NAME
@@ -245,7 +245,7 @@ sub init_value {
return @values;
}
-=head2 model_validate
+=head2 validate_model
Validates profile items that are dependent on the model.
Currently, "unique" fields are checked to make sure they are unique.
@@ -255,7 +255,7 @@ field values entered in $field->value at this point.
=cut
-sub model_validate {
+sub validate_model {
my ($self) = @_;
return unless $self->validate_unique;
View
16 lib/HTML/FormHandler/Model/DBIC.pm
@@ -6,7 +6,7 @@ use Carp;
use UNIVERSAL::require;
use DBIx::Class::ResultClass::HashRefInflator;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
=head1 NAME
@@ -30,7 +30,7 @@ You can specify the "item_class" in your form:
has '+item_class' => ( default => 'User' ); # 'User' is the DBIC source_name
The 'item_id' and 'schema' must be passed in when the form is used in your
-controller. ( also see L<Catalyst::Controller::Role::HTML::FormHandler> )
+controller.
If an 'item' is passed in, the 'item_id', 'item_class', and 'schema' will
be derived from the 'item'.
@@ -66,10 +66,6 @@ L<HTML::FormHandler::Manual>
L<HTML::FormHandler::Field>
-L<Catalyst::Controller::HTML::FormHandler>
-
-L<Catalyst::Controller::Role::HTML::FormHandler>
-
=head1 METHODS
=head2 schema
@@ -613,14 +609,6 @@ sub resultset
The author can be contacted through the L<Catalyst> or L<DBIx::Class> mailing
lists or IRC channels (gshank).
-=head1 SEE ALSO
-
-L<HTML::FormHandler>
-L<HTML::FormHandler::Field>
-L<HTML::FormHandler::Model::CDBI>
-L<Catalyst::Controller:HTML::FormHandler>
-L<Rose::Object>
-
=head1 AUTHOR
Gerda Shank, gshank@cpan.org
View
BIN  t/db/book.db
Binary file not shown
View
6 t/process.t
@@ -6,7 +6,7 @@ use lib 't/lib';
BEGIN {
eval "use DBIx::Class";
plan skip_all => 'DBIX::Class required' if $@;
- plan tests => 18;
+ plan tests => 20;
}
use_ok( 'HTML::FormHandler' );
@@ -22,6 +22,9 @@ my $form = BookDB::Form::Book->new;
ok( $form, 'no param new' );
+$form->process( item_id => 1, schema => $schema, params => {} );
+is( $form->item->id, 1, 'get item from item_id and schema');
+
ok( !$form->process( schema => $schema ), 'Empty data' );
# This is munging up the equivalent of param data from a form
@@ -48,7 +51,6 @@ is( $form->value('format'), 2, 'get value for format' );
my $id = $book->id;
-
my $bad_1 = {
notitle => 'not req',
silly_field => 4,
View
0  t/script/bookdb_server.pl 100644 → 100755
File mode changed
View
0  t/script/bookdb_test.pl 100644 → 100755
File mode changed
Please sign in to comment.
Something went wrong with that request. Please try again.