[html-formfu] Modifying values in the form after loaded from DB
Leanan Sidhe
the.leanan.sidhe at gmail.com
Fri Apr 3 18:19:36 BST 2009
This ties in to my earlier question regarding converting values that are
submitted before placing them in the db. I figured out how to go about
doing this just fine, thanks to the Clarification of add_valid and me
realizing my controller wasn't calling things in the proper order.
But now I'm trying to convert from what is in the db, to a more sane value
for humans to read. I figured out that I need to use $field->default
instead of $form->add_valid (I think?).
Here's what I'm doing:
if ($form->submitted_and_valid) {
#process it, stuff it in the db
} else {
$form->model->default_values($c->model('DB::Thing'));
}
I've been looking through the code for HTML::FormFu, HTML::FormFu::Model,
HTML::FormFu::Model::DBIC, Catalyst::Controller::HTML::FormFu, etc.
After that call to $form->model->default_values, what happens? I see that
at the end of default values, there is a return $form. But I don't see
anywhere that is doing $c->stash->{'form'} =3D $whatever. My guess is I'm
just missing where ever that gets done (or it's some automagical thing).
I ask because in trying to figure out how I should do this, I thought I'd
look and see how default_values work. I thought that it'd be as simple as:
$form->model->default_values($c->model('DB::Thing'));
my $converted_form =3D do_conversion($form);
$c->stash->{'form'} =3D $converted_form;
Or perhaps even:
$form->model->default_values($c->model('DB::Thing'));
my $converted_form =3D do_conversion($c->stash->{'form'});
$c->stash->{'form'} =3D $converted_form;
But neither of those seems to work. The best I've been able to get, no
matter what I try, is that the form contains what is in the db
pre-conversion, or the form contains a bunch of empty data. What am I
missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090403/82=
5dcb5c/attachment.htm
More information about the HTML-FormFu
mailing list