Re: Using Fly
[email protected] (Geoff Youngs) Mon, 06 Sep 1999 16:28:31 +0100
| Newsgroups | perl.riscos |
|---|---|
| Message-ID | <493D5BFC7A%[email protected]> |
In message <[email protected]> Nik Gare <[email protected]> wrote: > On 06 Sep, iain truskett <[email protected]> wrote: > > On 6 Sep, you wrote: > > > > <big snip> Hi, I'm still going through all the stuff on Fly, I might > > > even understand it eventually! I have another small problem, > > > concerning CGI.pm As I understand, this is in the zip file in the > > > library directory in !Perl. If I have a line such as: > > > > > > my $favourite = param ("flavour"); > > > > > > Perl doesn't understand this and says > > > > > > undefined subroutine &main: param called at ...<snip> > > > > > > The param function should be included in CGI.pm (I think), so do I > > > actually need to 'install' CGI.pm somewhere, or am I missing > > > something (probably my brain :-) ) > > > You *are* putting "use CGI;" at the top of your script, right? > > > Straight(ish) out of Learning Perl (hence the strange spelling :-) ) I know > there is a blindingly obvious reason why the script doesn't work, but as > usual I can't find it! Are you using it with NetPlex? The CGI module expects to find the data in QUERY_STRING, but NetPlex sticks it in CGI$Query_String or similar. It's easiest if you don't use modules, as they aren't always consistent from port to port. Try cgi-lib.pl or write it all by hand. If you're not sure exactly what to do, rip the form parsing functions out a script at Matt's Script Archive (IIRC, http://www.worldwidemart.com/) or try the below (shamelessly ripped off Matt's original idea). sub get_form_data { # Read all form data into $raw_form, regardless of submission type if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $raw_form, $ENV{'CONTENT_LENGTH'});} elsif ($ENV{'REQUEST_METHOD'} eq 'GET') { $raw_form = $ENV{'QUERY_STRING'};} # Split the data line up into pairs of type 'name=value' @data = split(/&/, $raw_form); foreach $data (@data) { # Separate name and value pairs into $name and $value ($name, $value) = split(/=/, $data); # Translate all pluses to spaces $value =~ tr/+/\ /; # Replace all %FF type sequences with the ASCII equivalent. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Store data in an associative array $FORM_DATA{$name} = $value; } } To use it, add the above to the bottom of the script and include a &get_form_data; early on in the script (before you try to access any form data). It doesn't matter whether the form's action is GET or POST, the above will extract all the data. To access the data use $FORM_DATA{'name'} where name is the name of the form element, e.g. <INPUT TYPE="Text" NAME="city" VALUE="London"> would return the value in the text box (initially London) to $FORM_DATA{'city'} To test it on NetPlex, change all the vars to CGI$<original name>, removing the underscores. HTH, Geoff. -- Geoff Youngs Technical Director solutions.web - Website Designers Tel. (023) 92 412964 Web : http://www.solutionsweb.co.uk/ "I believe it's very hard to have fun in Iceland without fish being involved in some way." -- Looking for a good place to party (Terry Pratchett, Johnny and the Dead)