At 5:45 AM +0200 10/18/09, adlai burman wrote:
Hello and help, please.
This is actually a CGI/Perl issue I am having but Perl seems to be the
closest forum here.

I am having a very simple (hence very frustrating) problem with a CGI/
Perl script. For some reason if I pass things from a checkbox they all
get passed fine but the last item is passed twice. I have excised a
paired down script with the html and perl components. I am at wit's
end with this. Please someone tell me what is going on.

From fill_pg.html:

<HEAD>
<TITLE>Fill pg</TITLE>
</HEAD>
<BODY BGCOLOR=white>

<FORM NAME=fill_pg ACTION="http://10.0.0.139/cgi-bin/fill_pg.pl";
METHOD="post">

<h1>Please select the plants to search<br></h1><br>

<input type=checkbox name=access value=AJ400848>Spinacia oleracea
<input type=checkbox name=access value=DQ020642>Antirrhinum majus
<input type=checkbox name=access value=AJ506156>Amborella trichopoda
<input type=checkbox name=access value=AP000423>Arabidopsis
thaliana<br>
<input type=checkbox name=access value=AP009369>Arabis hirsuta
<input type=checkbox name=access value=AM711640>Cuscuta reflexa
<input type=checkbox name=access value=AJ316582>Atropa belladona
<input type=checkbox name=access value=AP009370>Barbarea verna<br>

<h1>Please select the gene you are looking for:</h1>
<select name=gene>
   <option> petD
   <option> petB
   <option> rpoA
</select>

<CENTER>
<INPUT TYPE="submit" VALUE="SUBMIT">
</CENTER>
</FORM>
</BODY>

Now the Perl script:

#!/usr/bin/perl


You should always have the following two lines in your script:

use strict;
use warnings;

You might also want to consider using the CGI module, as it will save you the work of parsing your form input.


print "Content-type: text/html\n\n";
$forminfo = <STDIN>;

@key_value_pairs = split(/&/,$forminfo);
foreach $pair (@key_value_pairs){
    ($key,$value) = split(/=/,$pair);
    $value =~ s/\+/ /g;
    $value =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C", hex($1))/eg;
    $FORM_DATA{$key} = $value;
print $FORM_DATA{'access'};


You are storing a key-value pair of variables in your hash, but printing the value for the key 'access'. What happens when the key is not 'access'. Do you not expect to get the key 'gene' in your input?

print"<br>";

print $FORM_DATA{'gene'};


You are printing the value of the 'gene' entry for each entry in your form input. Since the 'gene' entry is the last one in your input, you only see its value once, but you are really printing it three times. The first two times the hash value is null.


}

If I choose, say, the checkboxes corresponding to, say, AJ400848
and AJ316582 and the pulldown list item, say, petD .... this is what I
get:
AJ400848
AJ316582
AJ316582
petD

How do I make it stop doing this? Please help.

If you are having trouble understanding why your hash contains what it does, use the Data::Dumper module to print its contents:

  use Data::Dumper;
  ...
  print Dumper(\%FORM_DATA);



--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to