[Catalyst] Class::DBI::FromForm;

Marcello m.romani at spinsoft.it
Tue Jul 26 11:34:44 CEST 2005


Krzysztof Krzyzaniak ha scritto:
> I need some explanation. I am quite fresh with Class::DBI, previously 
> always I've used only DBI with explicite SQL code. Now I am trying avoid 
> using sql code (for fun, for test) and now I stuck.
> 
> I have some HTML form, which send to controller some data:
> 
> sub do_add : Local
> {
>     my ($self, $c) = @_;
> 
>     if ( $c->req->params->{'upload_file'} eq 'yes' )
>     {
>     ... some parsing & checking there
> 
>         TrackCD::M::CDBI::Record->create_from_form( \%hash );
>         $c->forward('/tcd/record/list');
>     }
> }
> 
> I have of course Model for TrackCD::M::CDBI::Record (with demanded 
> plugins) but I need information how to build %hash - maybe there is some 
> 'easy and magic' way?
> 
>   eloy

You should use
Catalyst::Plugin::FillInForm and
Catalyst::Plugin::FormValidator,
then your do_add method should have some code like this:

my $profile = { optional => TrackCD::M::CDBI->columns } # see 
Data::FormValidator docs
my $results = $c->form($profile);	# validate submitted data
unless($results->has_missing() || $results->has_invalid()) {
	TrackCD::M::CDBI::Record->create_from_form($c->form);
}

Marcello



More information about the Catalyst mailing list