Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Problems? Is your data what you think it is?
 
PerlMonks  

Form validation and best practice in CGI::Application

by Anonymous Monk
on Oct 28, 2011 at 01:58 UTC ( #934292=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I've been learning Perl for the past month or so, and have decided to reinforce my understanding (and add to it!) buy using CGI::Application to create a very basic forum (only single level posts, no replies, no user accounts, etc). Everything has been going great up to this point, but I've hit a road block: I'm unsure of the best practice when it comes to validating form input, and issues with fitting it into the CGI::Application MVC paradigm. At first, I had an if, else statement in my 'newpost' runmode that would check to see if the user had entered any information. If they had not yet entered information, the HTML::Template page that has the form on it would be displayed. I had the submit button on that form call the 'newpost' runmode, expecting that since the user had just entered information, the code in my else statement would be executed (in the else statement I wrote to the DB and then wanted to redirect to the 'viewall' posts runmode). After fiddling around with that, I couldn't get it working how I imagined. I then created a new runmode called 'process' that would be called upon submission of the form. However, I recall reading in the CGI::Application documentation that all runmodes should return some kind of output (html). I know I could just write another external script to validate the form, but to me that's getting away from the "all code in one place" idea that CGI::Application seems to promote. Any ideas how I should go about approaching this? Thanks for your time!

Comment on Form validation and best practice in CGI::Application
Select or Download Code
Re: Form validation and best practice in CGI::Application
by monktopher (Novice) on Oct 28, 2011 at 02:00 UTC
    Sorry about posting as anonymous, I thought I had logged in before posting.
Re: Form validation and best practice in CGI::Application
by Anonymous Monk on Oct 28, 2011 at 03:42 UTC
      Thanks for all the links. I've been going through them the past couple of days. Lot's of good info!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://934292]
Approved by BrowserUk
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-04-18 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls