SpritusMaximus has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone run into a problem where CGI returns no variables? I'm doing user registration for my website, and I have (yet another) odd problem. One form works fine, but the other form returns no data.

If I use this simple script:

#!/usr/bin/perl print "Content-type: text/html\n\n"; foreach my $scalar (<STDIN>) { print "Data received is: " . $scalar . "\n\n"; }


I get output like this:

-----------------------------18908589074631857321096704418 Content-Disposition: form-data; name="TestFormField" 435435 -----------------------------18908589074631857321096704418 Content-Disposition: form-data; name="Submit" Continue -----------------------------18908589074631857321096704418--

However, if I use this script:

#!/usr/bin/perl use CGI qw (-debug); use CGI::Carp qw (fatalsToBrowser); print "Content-type: text/html\n\n"; print "Dump is:\n"; my $CGIValues = new CGI; $CGIValues->Dump();


The dump returns no data whatsoever. My web server error logs and access logs report no anomalies. Where could I go look to find the answer to this (or at least some clues)?

Thanks,
Josh

Replies are listed 'Best First'.
•Re: CGI returns no data
by merlyn (Sage) on Dec 20, 2003 at 20:33 UTC
    $CGIValues->Dump();
    What are you expecting that to do, when it says this on the manpage:
    The Dump() method produces a string consisting of all the query's name/value pairs formatted nicely as a nested list. This is useful for debugging purposes: print $query->Dump

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: CGI returns no data
by b10m (Vicar) on Dec 20, 2003 at 20:31 UTC
    See CGI for more, but it looks like you don't want to actually print the output ;) Taken from that same URL:
    print $query->Dump
    So in your case, try this as your last line:
    print $CGIValues->Dump;
    --
    b10m
Re: CGI returns no data
by jeffa (Bishop) on Dec 21, 2003 at 04:45 UTC
    Just a couple more suggestions:
    1. If you are going to use CGI.pm, then get into the habit of using the header() method to generate the content header. In fact, that method and param() are sometimes the only methods i need from CGI.pm:
      use CGI qw(param header); print header; if (param('form_submitted') { # process form and print results/errors, maybe reprint form } else { # print form }
    2. Don't use the name $CGIValues for a CGI.pm object. $CGI or $q will do just fine. The reason is that you don't have a handle to the $CGIValues, you have a handle to a CGI.pm object. If you want a handle to the CGI.pm parameter values, do the following:
      my $q = CGI->new; my @CGIValues = values %{$q->Vars};
      Seems more appriate for a variable named CGIValues ... although technically the values belong to the parameters, not CGI. More useful and meaningful is:
      my %param = $q->Vars; #update: typo (was %q->Vars) thanks BUU

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: CGI returns no data
by CountZero (Bishop) on Dec 21, 2003 at 13:31 UTC
    If you use CGI just for the headers, parameter parsing, cookie handling and file uploads (i.e. everything except the HTML-routines), you could consider using CGI::Simple instead. It is a drop-in replacement for CGI.pm

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law