[Catalyst] Recommend methods for form handling

Hartmaier Alexander Alexander.Hartmaier at t-systems.at
Fri Jan 19 12:04:31 GMT 2007

I don't like it because it breaks UTF-8 because HTML::Parse doesn't support it and some characters like > are html escapted.
On top of that it slows down every request by a factor of two because of the html parsing/html building.
Using a form generator which can be filled with the cgi params is much cleaner imho.

The _from_db and _from_params methods are one per object (form) and with them I can control where the data for the form comes from, which is needed to fill for example the edit form on first load with the data from the database.
I don't have a method from stash to db, my do_edit method looks like this:

# get Data::FormValidator profile
# update request
$obj_request->update_from_form( $c->form );


> -----Original Message-----
> From: Ian Docherty [mailto:catalyst at iandocherty.com]
> Sent: Wednesday, January 17, 2007 10:07 PM
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] Recommend methods for form handling
> Hartmaier Alexander wrote:
> > Hi Jim!
> >
> > I don't recommend the use of FillInForm, I dropped it finally two
> weeks ago when I had time to refactor my Catalyst apps that used it.
> > Now I handle forms by putting the data they should show on the stash
> with $c->stash->{form_data}->{fieldname} = 'value';
> > I have to private actions to do this, one _from_db and one
> _from_params.
> > Their names should be self-explanatory.
> > E.g. the edit action forwards to the _from_db method on first load of
> the form which is detected by checking for method POST and the value of
> the submit button, else the _from_params.
> >
> > With this I don't have to overwrite the cgi params and have full
> control of what my form should display.
> >
> > Those values are used in my templates like value="[%
> form_data.fieldname %]".
> >
> > You can look at FormBuilder which should be pretty good from what I've
> heard.
> > I'll wait for Reaction and invest some time in learning how to use it
> when it's done.
> >
> > Ah, and I use Plugin::FormValidator for the form validation. A private
> do_form method does this and is used for both add and edit methods.
> >
> > -Alex
> >
> I tried this approach myself some time ago, before I moved to FillInForm
> but I found in cumbersome. I would like to you say what you did not like
> about FillInForm and why you don't recommend it?
> The trouble with your _from_db and your _from_params approach (which is
> similar to the approach I originally used) is that you have to write a
> long sequence of copies from one place to another and to keep track of
> all the things you have to copy, adding new ones when you add form
> elements. It breaks the DRY approach since you now have similar code in
> at least two or three places. (from the db to the stash, from the params
> to the stash, from the stash to the db).
> What I especially like about using FillInForm is that if I have a form
> that edits (say) a user, I simply pass the user object on the stash. The
> template then refers to [% user.firstname %], [% user.lastname %] etc.
> and FillInForm does the rest when the form is re-submitted. It makes my
> controllers so much simpler.
> Regards
> Ian Docherty (IcyDee)
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-
> archive.com/catalyst at lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/

T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then delete this e-mail immediately.

More information about the Catalyst mailing list