[Catalyst] Rails-like form helpers

Jon Warbrick jw35 at cam.ac.uk
Fri Oct 13 14:42:00 CEST 2006


Sorry, I've been a bit slow replying to your questions :-)

On Thu, 21 Sep 2006, Zbigniew Lukasiak wrote:

> I don't know if I grap the idea of the helpers in full - could you explain
> their functions here in short?  For me it looks like they just create form
> elements just like the $w->element('...', '...') does.  

Yes, that's about it. They are just shortcuts for use in templates to 
create form elements, except that

  1) They deal with the stickiness/defaulting for you; and

  2) They know how to name the elements to make updating the underlying 
     model objects easier. So a text box for editing the 'name' field of a 
     person record might be called 'person.name' (see below).

  2) They know about the error flags that appear in the model objects 
     following validation failure and so can adapt their behaviour 
     accordingly (display with error flags, add error messages, etc). 

> There is something
> also about using them for the updates - could you a bit elaborate on that?

On form submission, these parameters are parsed into data structures in 
the equivalent of $req->parameters (so the edited name value from above 
might be in $req->parameters->{person}->{name}). The huge value of this is 
that the model objects can directly accept these structures for creation 
or update, e.g.

  $c->model('Person')->update($req->parameters->{person});

> HTML::Widget also works on the update side - at least can check the
> constraints, but it does not set values of an object - do the RoR helpers?

A lot of this functionality exists in HTML::Widget. The main difference 
seems to be that in HTML::Widget you decide how you want your form 
controls to look in the model class, and in Rails you do it in the 
template.

Jon.

-- 
Jon Warbrick
Web/News Development, Computing Service, University of Cambridge



More information about the Catalyst mailing list