[Catalyst] Form processing with catalyst, html::widget, and template toolkit

Todd Charron todd at neteffect.ca
Fri Jan 27 18:24:58 CET 2006

On Friday 27 January 2006 11:50, Thomas Klausner wrote:
> In each controller, I have a method that generates a widget, eg:
> sub widget_register {    # create the 'register' widget
>   my ($self,$c)=@_;
>   my
> $w=$c->widget('register')->method('get')->action('/users/do_register');
> $w->element('Textfield','email')->label('Email');
>   $w->element('Textfield','name')->label('Name')->value('test');
>   ... # more fields, constraints etc
>   $w->indicator('email');    # field to check if theres data
>   $w->element('Submit')->value('register!');
> }

Can you clarify exactly how the indicator is used?  Can it be any element or 
do you have to set it for each element that is required to be submitted?  How 
is it checked for submission?  In this case it looks like the action of the 
form does all the work and the indicator itself does nothing.  Is that 

> Now for form submission:
> sub do_register : Local {
>     my ($self,$c)=@_;
>     my $w=$self->widget_register($c);   # get the widget
>     my $result = $w->process($c->req);  # pass the request to the widget
>     if ($result->has_errors) {
>        # error!
>     } else {
>        # create object
>     }
> }

Is there a way to have the action of the form be the same URL as the form 
itself?  How do you re-populate the form fields? 

Sorry for the barrage of questions but I'm really curious.  

Ideally what I'd like to have is if there are errors the form re-populates 
itself with the errors marked for correction by the user.  Once the form is 
complete we can either just place a message on the same page or in other 
instances redirect to another page.

The other feature that formbuilder had which was very nice was javascript 
validation.  I see some references to javascript validation but no details on 
how to actually use it if the functionality is indeed complete.



More information about the Catalyst mailing list