[html-formfu] DB-driven select boxes, checkbox groups and radio groups

Brian Cassidy brian.cassidy at nald.ca
Fri Jun 29 16:26:42 GMT 2007


Hey All,

A common theme we're running into is providing select boxes, and 
(radio|checkbox) groups with data stored in the database.

Select boxes seem to be pretty easy

package MyApp::Form::Element::Thingy;

use base qw( HTML::FormFu::Element::select );

sub new {
     my $self = shift->SUPER::new( @_ );

     my $c = $self->form->stash->{ context };
     my $thingies
         = $c->model( 'DB::Thingy' )->search( { foo => bar } );

     $self->options(
         [   {},
             map {
                     { label => $_->name, value => $_->id }
                 } $thingies->all
         ]
     );

     return $self;
}

1;

Is this good idea? Is there a recommended way?

Creating a group of checkboxes and/or radio buttons from a db table 
seems to be a much harder problem -- is there a recommended solution for 
that as well?

-Brian



More information about the HTML-FormFu mailing list