[Catalyst] Class::DBI::FromForm;

Krzysztof Krzyzaniak eloy at kofeina.net
Tue Jul 26 23:34:04 CEST 2005


Krzysztof Krzyzaniak wrote:
> Marcello wrote:
> 
>>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
> 
> 
> Hmm. There is one problem. I don't have $c->form
> 
> Caught exception "Can't locate object method "form" via package 
> "TrackCD" at 
> /home/eloy/site/trackcd/script/../lib/TrackCD/C/TCD/Record.pm line 124."


OK! My bad! I didn't load Catalyst::Plugin::FormValidator. Now 
everything works. Thank you.

   eloy
-- 
-------e-l-o-y-----------e-l-o-y- at -t-r-a-n-s-i-l-v-a-n-i-a-.-e-u-.-o-r-g------

        jak to dobrze, że są oceany - bez nich byłoby jeszcze smutniej



More information about the Catalyst mailing list