[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] Re: Dispatch Apache typo



Stewart Heckenberg wrote:

CCing the C::A list for the benefit of others... (hope you don't mind Stewart)

> Hi again Michael,
> 
> Apparently using Dispatch doesn't take notice of hidden rm fields in
> forms, and so the only way to specify the runmode a form submits to is
> to set the form html tag's action attribute, e.g.
> 
> <form method="post" action="/someapp/arunmode">
>  <input name="blah" type="text">
>  <input type="submit">
> </form>
> 
> Where someapp is the name of desired app and arunmode the desired rm.
> 
> Is this the best/right way to use forms with Dispatch? 

Yes and no. If you set the RM in the url, then Dispatch will force C::A to use
that. Else it will let C::A do it's normal thing. Typically with forms, since
you know where the form is going to submit to, it doesn't really matter whether
you specify that as part of the action or a hidden attribute.

>I've noticed
> that without specifying the action attribute of the form tag (which is
> usually the case with normal cgiapps, because the hidden rm field
> takes care of things) that the runmode that was currently displayed
> will re-display. 

It depends on how you have your dispatch table set up. A rule like this would
let you use the URL for the module and the rm input for the run mode.

  ':app/' => { prefix => 'MyApp' },

> It's thus possible to test for $self->query (i.e. the
> old-fashioned way of testing whether a CGI form was submitted) and
> then redirecting/forwarding from there, but that's kind of messy
> compared to just specifying the target runmode in the form action
> attribute.

Yeah, that's messy. Usually if I'm using a form, I just put the module and run
mode into the URL.

> Also when using form action attribute, if I want to add a param such
> as an id (which I would specify in the dispatch setup with :id) then
> I've found I have to make sure I append that id value to the action
> attribute, i.e. /someapp/arunmode/23... but that's kinda messy too
> because i then have to grab that via self->param('id') and then spit
> it out via either a template variable or some other means rather than
> it persisting as part of the url.

In that case, I would just put the id in the form as a hidden input and retrieve
it with $self->query->param('id'). Dispatch is nice for making pretty URLs and
making things more RESTish, but it shouldn't replace the flexibility of forms,
especially with things like HTML::FillInForm make forms so easy to use.

-- 
Michael Peters
Developer
Plus Three, LP


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.