Well, anyone who's been around here for a while knows that I can't avoid a node like this :)

Your code contains virtually all of the errors that I mentioned in this node. It is not strict compliant and if any form data contains a comma, then your habit of separating multiple values with a comma will not work.

Your line to deal with Server Side Includes is broken for two reasons. See use CGI or die; for a footnote explaining both problems.

higle wrote:

...I couldn't find a straightforward form parsing routine on PM...

It's called CGI.pm. If you need a snippet to grab your form data, try this:

use strict; use CGI qw/:standard/; my %form = map { $_, @{ [param($_)] } > 1 ? [param($_)] : param($_ +) } param();

If you have a single value for a form element, the value in %form will be a scalar. Otherwise, it will be an arrayref. For example, with the following query string:

color=red&color=blue&name=Ovid

You will get the following data structure:

%form = ( 'name' => 'Ovid', 'color' => [ 'red', 'blue' ] );

I know that it's not a lot of fun to see your code commented upon like this. I apologize in advance for any offense, but trust me on this: properly handling form data is considerably more difficult than most people think. I've been doing this for quite a while and while I think I could write my own better than most, I also know that it would still be buggy.

Cheers,
Ovid

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: Simple CGI Form Parser by Ovid
in thread Reaped: by NodeReaper

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.