|Perl: the Markov chain saw|
Mixing POST and GET with CGI::Applicationby c4onastick (Friar)
|on Mar 06, 2009 at 18:58 UTC||Need Help??|
c4onastick has asked for the
wisdom of the Perl Monks concerning the following question:
I haven't done much web development in Perl as of yet (I came to Perl from PHP to get away from the web), but decided to get my feet wet a bit with a new project at work. I stumbled across CGI::Application the other day while getting started and thought it'd be great for a rapid development framework (yet another reason I came to Perl from PHP: CPAN! Back in my PHP days I ended "rolling my own" pseudo-CGI::Application for PHP.)
CGI::Application's interface is great (much better than mine!), it gives you a nice MVC canvas to start painting your site upon. However, I did run into a bit of a problem trying to pass variables via both GET and POST, which is typically how I've handled form submissions before (i.e. use the form method "POST" and an action of something like "index.cgi?page=submit_form")
Here's a simplified version of what I've got so far:
With templates that look like:
When testing this locally on Apache 2.2 (in Win32), CGI::Application seems to choke, it would make the switch to run mode "mode2" (the address bar would have "rm=mode2") but it would still display "mode1" (the form page), which makes me think it caught some exception and defaulted to "mode1". Unfortunately, I wasn't able to find anything interesting in the Apache logs. I tried a number of things to try to manually debug but with little luck.
Changing to 100% POST did work as expected though...
So, that leads to my question: How do you handle both POST and GET with CGI::Application?
I did some looking through CGI.pm and it looks like it handles POST and GET via two different methods: "param" (for POST) and "url_param" (for GET). "url_param" doesn't appear anywhere in CGI::Application and I was able to isolate CGI::Application as the source by writing it "old-school". The following works as expected:
Thanks in advance for your help!
Update: I'm using: