[Catalyst] Form handling, urls and web design

Alex Kavanagh alex at tinwood.homelinux.org
Tue Jan 24 09:48:05 CET 2006


At Mon, 23 Jan 2006 16:26:25 -0600,
Brandon Black wrote:
> 
> On 1/23/06, Alex Kavanagh <alex at tinwood.homelinux.org> wrote:
> > Hi
> >
> > Yes, another post, but I'm beginning to get into this and questions
> > just keep popping up.
> >
> > Currently, I'm wondering what the best way of handling forms is in the
> > context of urls and what to do with error messages.
> >
> > I have a system going, but I'm curious as to what others have done in
> > solving this particular design problem.
> >
> 
> You could also consider changing your url layout to be more like:
> 
> URLs:
> /myapp/users/list
> /myapp/users/add
> /myapp/users/add_confirm
> /myapp/users/view[/username]
> 
> myapp::users.pm:
> 
> sub default ( redirects to users/list )
> sub list/add/add_confirm ( do the obvious )
> sub view : Local {
>    my ($self, $c) = @_;
> 
>    my $username = $c->req->args->[0];
> 
>    $c->res->redirect('list') if !$username;
> 
>    ......
> }
> 
> Now the usernames and the other actions are not stepping in the same
> URI path-space, the username is a simple $c->req->args thing, and no
> regexes or magic selectors involved.  Basically, the extra path
> information on the end of view is PATH_INFO, which becomes the
> $c->req->args arrayref.

I like the idea of getting rid of the Regex (plus the nice syntax for
getting the extra bits of path from the @_ var, thanks Yuval), but, having slept on
it, I remembered *why* I did it this way.

I didn't want to use the a separate url for posting the form (from the
one displaying the form) because if validation failed then, although
the form could be redisplayed, the url would now be different.

e.g.

/myapp/users/add   - when the form is display first time.
/myapp/users/add_confirm - when the form fails validation and is
                           redisplayed 

I reasoned that this might be disconcerting to the user.  The only way
I could think around it was a redirect but then I would lose the error
messages and the bits that were already filled in.

However, I agree with getting rid of the selector magic - it seemed
like such an elegant idea when I came up with it, but it just seems
complex and hides too much of what is actually going on, plus it seems
that I'm missing something fundamental about how to use the Catalyst
dispatching framework.

-- 
Alex.



More information about the Catalyst mailing list