wrt radioboxes on forms/dbic; I have been doing a true/false/null using the following:
invited: label: Invited? options: 1=Yes, 0=No required: 0 As this is not required, if nothing is sent back the value will be undef => null; otherwise 1/0 will be returned based on yes/no response. To remove null, simply set required to 1. re the easy solutions presented earlier in the thread for sticking a form into a db and back again; I don't ususally make the code that simple because it could open up injection attacks and doesn't work too well with more complex forms or fields. I usually explicitly list which fields i want to use so then a typo in the form or a forgotten/newly added field in the form will not allow remote users to mess with bits of the database you don't want them to mess with. I guess you could probably use db column permissions to do that db-side though. Mark On Sunday 18 February 2007 1:01 pm, Carl Franks wrote: > On 18/02/07, RA Jones <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] wrote: > > > Hi Everyone, > > > > > > I have been experimenting with Catalyst::Controller::FormBuilder. I'm > > > trying to provide an edit form for objects read from and written to the > > > DB via DBIx::Class. Have FormBuilder automatically load the data from > > > DBIC into the form seems pretty easy with something like: > > > > > > my $widget = $c->model('MyAppDB::Widget')->find($id); > > > my $form = $self->formbuilder; > > > $form->values($widget->get_columns); > > > > > > > > > However, an elegant way of writing the data back out is not jumping out > > > at me. I know I could manually copy each field out of the $form object > > > to my $widget object, but it seems like there should be simple way to > > > do it all in one line like I got with the > > > "$form->values($widget->get_columns);" above. > > > > > > Any suggestions? What are other folks doing for C::C::FormBuilder and > > > DBIC? > > > > I'm pretty new to this, but this is what I did: > > > > sub edit : Local Form { > > > > # get data into form pretty much as above, then: > > > > if ( $form->submitted && $form->validate ) { > > $c->stash->{user} = $user; > > $c->forward('do_edit'); > > } > > > > sub do_edit : Private { > > my ($self, $c) = @_; > > my $form = $self->formbuilder; > > my $fields = $form->field; > > $c->stash->{user}->update($fields); > > $c->flash->{status_msg} = 'User updated'; > > $c->response->redirect( $c->req->base . 'users/view/' . > > $c->stash->{user}->id ); > > } > > > > Not sure if it's the 'best' way, but it works. Will be interesting to > > see what other suggestions you get. > > It might be worth looking at the code for DBIx::Class::HTMLWidget for some > ideas > http://search.cpan.org/src/ANDREMAR/DBIx-Class-HTMLWidget-0.09/lib/DBIx/Cla >ss/HTMLWidget.pm > > When you're populating the form from the database, would your > $form->values($widget->get_columns); > correctly set select menus? > > Also, (for all browsers that I'm aware of) no value is sent back to > the server for unchecked radioboxes - so it'd be worth checking > whether the "$fb->field" solution handles this properly. > (I don't know, as I've only read the formbuilder docs, I've never used it). > > Cheers, > Carl > > _______________________________________________ > List: Catalyst@lists.rawmode.org > Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ > Dev site: http://dev.catalyst.perl.org/ _______________________________________________ List: Catalyst@lists.rawmode.org Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/ Dev site: http://dev.catalyst.perl.org/