perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brett W. McCoy" <bmc...@chapelperilous.net>
Subject Re: weird problem. Lost of the POST data
Date Mon, 04 Feb 2002 16:31:15 GMT
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.


Mime
View raw message