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!


In reply to Form validation and best practice in CGI::Application by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.