Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

STDIN ..???

by virtualweb (Sexton)
on Jan 03, 2010 at 02:20 UTC ( #815365=perlquestion: print w/ replies, xml ) Need Help??
virtualweb has asked for the wisdom of the Perl Monks concerning the following question:

Hi:

Im trying to make a generic Form Handler script, (so the script will not know the field names).

I downloaded many free readily available Form Handler scripts just to see how they handle the collection of "names" and "values" from the HTML form.

All of them have a parsing routine.

But my script doesnt work with a parsing routine since Im using:

use CGI
$q = new CGI;

So basically if I wanted to use file names I would do this:

$Whatever = $q->param('Whatever');

But the thing is that the script is supposed to be generic.. in other words handle any number of field names not knowing the field name previuosly.

I found a small snippet of code to get any info coming to a script

while ($line = <STDIN>) { chomp $line; #do whatever must be done }

But I understand this is used to received data from a file.

Is there a comparable snippet of code to received any data from a form without a parsing routine..??

Comment on STDIN ..???
Download Code
Re: STDIN ..???
by ikegami (Pope) on Jan 03, 2010 at 03:00 UTC

    [ Please remove the <b> tag, or at least match it with a </b> tag. ]

    Is there a comparable snippet of code to received any data from a form without a parsing routine..??

    That makes no sense. The data from the form is sent as an HTTP request, which itself is sent as a bunch of bytes. Parsing means giving meaning to those bytes. You can't have the form data without parsing the request.

    My best guess is that you want to get the name of the submitted fields. If so, you can get those using my @names = $cgi->params()my @names = $cgi->param().

Re: STDIN ..???
by atcroft (Monsignor) on Jan 03, 2010 at 03:08 UTC

    Probably the two imporant items from the CGI.pm docs are the following:

    1. my @names = $q->param;, which gives all the parameter names, and
    2. my @values = $q->param('foo');, which would allow for multi-valued entries.

    Hope that helps.

      Yes this is the solution. The following is a simple demonstration that should be useful to the OP:

      #!/usr/bin/perl use strict; use warnings; use CGI; # print a simple content-type which will ensure we're not at # risk of XSS attacks, etc. print "Content-type: text/plain\n\n"; # get the CGI object my $cgi = new CGI; # for each parameter submitted foreach my $param ( $cgi->param() ) { # print the parameter and the value it contained. print $param . " " . $cgi->param( $param ) . "\n"; }
      Steve
      --
        # print a simple content-type which will ensure we're not at # risk of XSS attacks, etc. print "Content-type: text/plain\n\n";

        Just throwing this out there. IE does not respect content type headers over some of its other content heuristics and some servers write their own headers no matter what the CGI sends. So that might not be safe in edge cases. :(

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2014-12-27 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls