Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Does CGI.pm have a limit on information passed?

by c (Hermit)
on Nov 06, 2001 at 08:26 UTC ( [id://123502]=perlquestion: print w/replies, xml ) Need Help??

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

i am using cgi.pm to pull the returned values for a web-based form with the following code:

## grab form input my $query = CGI->new(); ## grab form field and stick values in hash my @formfields = $query->param; for my $field(@formfields) { if ( $field eq 'recipient' || $field eq 'replyaddr' || $field eq 'required' || $field eq 'replyname' || $field eq 'title' || $field eq 'redirect' || $field eq 'subject' || $field eq 'postdir' || $field eq 'body_message' || $field eq 'return_link_title' || $field eq 'return_link_url' ) { $CONFIG{$field} = $query->param($field); } else { $FORM{$field} = $query->param($field); } }

now, this seems to work fine and the values are stuffed into one of two seperate hashes. now i look through the %form hash and verify that all the form fields that i mark as required, are filled in

## each missed field is placed in a new array for my $i(@required) { chomp $i; if (!$FORM{$i}) { push @missed_fields, $i; } }

the @required array just simply a list of the form fields that need to be present.

what is odd is that sometimes, even though all the form fields have been filled in, the script pushes _all_ the form's fields into @misssed_fields as though cgi.pm hasnt extract any values for them. this seems to occur when a group of radio buttons are selected. it occurs whether or not the radio button form names are within the @required array or not. just having them selected seems to cause cgi.pm to freak.

does this sound at all logical or as a known issue? i can barely believe that it would since i would imagine that many sights are using radio buttons! the form is not especially large, only 30 fields to fill in. your input is very appreciated on this one!

humbly -c

Replies are listed 'Best First'.
(Ovid) Re: Does CGI.pm have a limit on information passed?
by Ovid (Cardinal) on Nov 06, 2001 at 09:11 UTC

    First, you have a slight bug in the loop. You want exists:

    ## each missed field is placed in a new array for my $i(@required) { if (! exists $FORM{$i}) { push @missed_fields, $i; } }

    I also took out the chomp as that simply removes the input record separator as defined by the $/ variable. Show us how you defined @required and that will help us out a bit more. Also, it will depend on the value of the radio buttons, so show us how those are defined in the HTML.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Does CGI.pm have a limit on information passed?
by kwoff (Friar) on Nov 06, 2001 at 09:19 UTC
    It looks reasonable so far, so I have a feeling it's not CGI.pm's fault here.. Debugging time. :)

    How did you make the radio buttons (CGI.pm or just HTML)? If CGI.pm, are you sure the syntax is correct? What are the names of the radio buttons in the HTML? Do the names match @required? Are the buttons inside of the <FORM> tags? Can you simplify the problem to using maybe one or two fields instead? Insert `print STDERR $field` statements and peek at the log (or use CGI qw(fatalsToBrowser).

      well, debugging time it is. i wanted to take out the @required variable completely. so, i wrote this quick little script

      #!/usr/bin/perl -w use strict; use POSIX qw(strftime); delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{'PATH'} = "/usr/bin:/usr/local/bin"; use CGI; $CGI::DISABLE_UPLOADS = 1; $CGI::POST_MAX = 1024; ## grab form input my $query = CGI->new(); my %FORM; ## grab form field and stick values in hash my @formfields = $query->param; for my $field(@formfields) { $FORM{$field} = $query->param($field); } print <<EOF; Content-type: text/html\n\n <html> <head> <title>Missed fields!</title> <body bgcolor=#FFFFFF> EOF for my $i(sort keys %FORM) { print qq|<li>$i : $FORM{$i}<br>\n|; } print <<EOF; </body> </html> EOF

      so once again though, i find myself eyeballing the radio buttons. when running this script, it churns out the values of the form's input. however, after selecting a couple of radio buttons, the return is actually null! as though nothing was passed into the hash at all.

      the radio buttons are written via regular html rather than through cgi.pm. an example of the radio button in the html is as follows:

      <td width="215"> <b> <font face="Arial, Helvetica, sans-serif" size="-1"> Yes <input type="radio" name="16accounts_receivable_pledge" value="yes"> No <input type="radio" name="16accounts_receivable_pledge" value="no"> </font> </b> </td>

      would the duplicate naming of the form field be causing problems?

      humbly -c

        Yes, the duplicate naming of fields will break your code as you're grabbing the params in a scalar context which will only return the first value. Here's a quick script that will show everything that is sent via your form (this is untested):

        #!/usr/bin/perl -wT use strict; use CGI qw/:standard/; use Data::Dumper; my %formdata = map { $_, @{[param($_)]} > 1 ? [param($_)] : param($_) +} param(); my $dump = Dumper \%formdata; print header, start_html, pre( $dump ), end_html;

        By the way, I'm glad to see that you've deleted dangerous environment variables and done other things to prevent hacking. Good job!

        Cheers,
        Ovid

        Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://123502]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-25 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found