I had similar problems not too long ago. 

The reason i believe is - 'You can only read POST data from STDIN
_once_'.

Aka, in a mod_perl script if you do something like:

my $q1 = new CGI;
my $q2 = new CGI;

my $name1 = $q1->param("name");
my $name2 = $q2->param("name");

$name2 will not be set if the data was POST'ed. This is because the $q1
object would have already read in data from STDIN and its now no longer
available to any other objects (including $q2). If it was a 'GET'
request, you would have no such problem as GET request query strings are
in $ENV{'QUERY_STRING'} and you can read from that as many times as you
like. 

The moral of the story being, for a single request never use more than
one CGI object (instantiate one and then pass it around)

cheers,

simran.





On Tue, 2002-02-05 at 03:31, Brett W. McCoy wrote:
> On Mon, 4 Feb 2002, Oscar Serrano wrote:
> 
> > some days ago I wrote to ask for this problem: The CGI.pm (sometimes) could
> > not receive the POST data. I tried all you recomended me here in the list.
> > But I still had the problem. Finally I decide to kick out CGI.pm and start
> > to use the old cgi-lib.pl. But I still had the same problem. Then I turnet
> > to Apache::Request, and since I use it, I've never had the same problem.
> > I just tell you because perphaps somebody may have the same problem. I
> > don't really understan if the problem is in mod_perl, in Apache, in Templat
> > Toolkit, in my ultrasecure patched kernel, in CGI.pm, but the point is that
> > Apache::Request seems not to loose any post data :-?
> 
> I had a similar problem a few days ago with a form processing engine I
> developed with mod_perl & Text::Template.  It takes a sequence of states
> out of a database and generates a 'wizard' to lead a user through a set of
> forms for, say, an employment application, membership application, etc.
> It uses a combination of CGI.pm for some of the high-level front end
> stuff, and uses the Apache::* modules for the lower level stuff (cookies,
> session management, etc).  Anyway, I had this wierd bug that instead of
> the straight sequence of forms, it would do the first form, then the
> second, the the first again, then the third, then the first again, then
> the fourth, and so on.  POST data was either missing, or incomplete, or
> was picking up values from several pages back.
> 
> I discovered what the problem was: I had a hash in one of my top-level
> class files (the system is object-oriented) that was being used as a
> global variable, a hash that had data that changed a lot.  Bad juju with
> mod_perl!  Moving the hash into the class constructor and making sure it
> got properly blessed into that class fixed the problem.
> 
> Another issue that can cause problems, especially using the OOP interface
> to CGI.pm under mod_perl, is using a global CGI object and using it inside
> of subroutines:
> 
> my $cgi = new CGI;
> 
> ...
> 
> sendmail('A message');
> 
> ...
> 
> sub send_mail {
> 
>       my $msg = shift;
>       print $cgi->h1('Something');
>       print $cgi->p;
>       ...
> }
> 
> This will cause some wierd problems.  The solution is to not use globals
> inside your subroutine, but pass what you need into it:
> 
> sendmail($cgi, 'A Message');
> 
> sub send_mail {
>       my $q = shift;
>       my $msg = shift;
>       ...
> }
>                                           http://www.chapelperilous.net/
> ------------------------------------------------------------------------
> When the wind is great, bow before it;
> when the wind is heavy, yield to it.

Reply via email to