[Catalyst] How to detect if the current form request is a post?

kakimoto at tpg.com.au kakimoto at tpg.com.au
Wed Apr 1 01:06:00 BST 2009


Thank you:)
Yep, and I am aware of GET as a form request method and yes, i hate it.
haha

K. akimoto


Quoting "J. Shirley" <jshirley at gmail.com>:

> On Tue, Mar 31, 2009 at 4:01 PM, <kakimoto at tpg.com.au> wrote:
> 
> >
> > hi all
> >
> >  In Ruby we can detect if the current form's request is a post or
> not.
> >
> > def controller_action
> >    if request.post?
> >              # Process post data as the user has submitted the
> form.
> >    else
> >        # Display form
> >    end
> > end
> >
> >
> > Looking at Catalyst::Request
> > (
> >
>
http://search.cpan.org/~mramberg/Catalyst-Runtime-5.71001/lib/Catalyst/Request.pm#$req-%3Eprotocol<http://search.cpan.org/%7Emramberg/Catalyst-Runtime-5.71001/lib/Catalyst/Request.pm#$req-%3Eprotocol>
> > ),
> > I found $req->method. The description says, "Contains the request
> method
> > (GET, POST, HEAD, etc)."
> >
> > So, in Catalyst, would it be sufficient for me to do something
> like:
> >
> > sub controller_action : Path('registration')
> > {
> >    if (($c->request->method eq 'POST') or ($c->request->method eq
> 'GET'))
> >    {
> >         # Process post data as the user has submitted the form.
> >    }
> >    else
> >    {
> >        # Display form
> >    }
> >
> >   return 1;
> > }
> >
> >
> > Comments? Thanks
> >
> >
> >
> Yes, as the docs say, that's what it is for :)
> 
> $c->req->method eq 'POST' will  do what you want.  You should not do
> any
> processing on a GET request, though.  It is just bad practice.
> 
> -J
> 






More information about the Catalyst mailing list