Hello Monks,

I've been reading this place for a little while, and now I have my first question, working on some bigger-than-usual project using Perl/mod_perl.

So at first, I was using CGI. Then, I decided to use HTML::Template for all my HTML generation needs, thus obsoleting the CGI.pm HTML related functions. Reading some posts here at PM, I then replaced CGI with CGI::Simple (the transition was easy as the latter is syntax compliant with CGI, and the project was still early). Doing some testings, I realised a script stopped working: it was supposed to get form data through POST, validate that data, and display an error message, provided some happened (followed by the form to reenter the data). Basic stuff, really.

Problem: the script wasn't getting the data as expected anymore. Trying to pinpoint the source of the problem, I wrote the following post_test.pl script:

#!/usr/bin/perl use strict; use warnings; use CGI::Simple; my $cgi = new CGI::Simple; my @params = $cgi->param(); print <<HEAD; Content-Type: text/html; charset=iso-8859-1 <html><head><title>CGI::Simple POST Test</title></head> <body> HEAD print($cgi->param($_) . "<br />") for (@params); # nothing printed if +@params is empty print $cgi->Dump; # for debugging purpose print <<FORM; <form action="post_test.pl" method="POST"> <p>Foo: <input type="text" name="foo" size="30" maxlength="255" va +lue="" /></p> <p>Bar: <input type="text" name="bar" size="30" maxlength="255" va +lue="" /></p> <p><input type="submit" name="submit" value="Test" /></p> </form> </body> </html> FORM

At first, nothing was available through $cgi->param(). Reading the docs, I added the $cgi->Dump and got my first clue:

$VAR1 = bless( { '.globals' => { # skipped }, '.cgi_error' => '500 Bad read on POST! wanted 31, got + 0', '.mod_perl' => 1 }, 'CGI::Simple' );

Replacing every occurence of CGI::Simple with CGI made the problem go away, of course. Further investigations led me to Ovid's CGI Course. The second lesson was particularly interesting:

If, for some reason, you need to debug the information being sent via a POST with a form "enctype" of "multipart/form-data", you can use the following script, which is what I used to produce the output above. It doesn't use CGI.pm as I need to read from STDIN directly, which is not possible if CGI.pm is used.
#!c:/perl/bin/perl.exe -wT use strict; my $buffer; read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); print "Content-type: text/plain\n\n"; print $buffer;

Unfortunately, that code didn't provide anything on my machine, whichever "enctype" I tried on that simple form. So, if any Monk among you has any other idea as to what I should try and do to find out about the origin of that problem, I will be forever grateful.

The setup:
Mac OS X 10.3.7 running Perl 5.8.1, mod_perl 1.26 and Apache 1.3.33.
Latest version of CGI and CGI::Simple, no forced install.

Thanks in advance.


In reply to CGI::Simple POST data trouble by Fang

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.