Both "static" and "dynamic" fields in a form

Skip to first unread message

Steve Rippl

Dec 1, 2011, 5:48:09 PM12/1/11
to formhandler

I have a form that has some "static" fields that are both inherited
from another form and then some more added via has_field in the
general declaration of the thing. I then have a bunch more very
repetitive fields I'd like to add dynamically as I could build the set
of fields and then loop through enough times just changing the names
as I go along. Is this possible? I've seen examples of adding to the
field list via process in the Controller, but I'd like to put this in
a sub within the file so as not to clutter up the controller.

Just coming over to this from HTML::FormFu and it seems pretty
impressive just how much is in FormHandler!


Gerda Shank

Dec 2, 2011, 12:03:24 PM12/2/11
Hi Steve:

There's quite a few ways to do this. The one that I'd try first is just
making a field_list sub in the form class. There's a couple of examples
in the documentation:

sub field_list {
return [
favorite_color => {
type => 'Select',
label_column => 'color_name',
active_column => 'is_active',

(Notice that it returns an arrayref in order to keep the order, but it's
actually a hashref.)

I'm not sure just how dynamic your extra fields are -- a role containing
the fields might work, possibly a parameterized role if you're changing
the names. But the field_list sub might be easier. Note that the
field_list fields are processed after the other fields, so if you need
them in a different order, you'll have to provide an explicit order on
the fields.

There are also examples in the t directory, in form_handler.t, errors.t,
etc. I recommend using the tests as examples, by the way :)

My new job uses FormFu, so I'm working on making it easier to make the
rendering/templates compatible. So if you have any suggestions in that
area, let me know.

One thing to point out is that FormHandler fields are built on new; you
don't add them after the form is constructed. But you can build in extra
fields and turn them on or off with 'active' and 'inactive'.


Rippl, Steve

Dec 5, 2011, 11:56:13 AM12/5/11
I ended up going with parameterized roles that I roll in with ->with_traits when creating the form.  I hadn't seen that that was possible with roles before, thanks for the great tip!

You received this message because you are subscribed to the Google Groups "formhandler" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Steve Rippl
Technology Director
Woodland Public Schools
360 841 2730
Reply all
Reply to author
0 new messages