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

Hi, I'm using IIS server and following code. I want to get value of textbox and checkboxes in perl file. But I'm getting null every time though text box have some value. Please please please someone through some light on the issue. my sample code is as below: a.html:
<html><head></head> <body> <form name='form' action = 'a.pl' method = 'get'> <input type="text" name="name" size="8" value="zzzz"> <input type = 'submit' value = 'SUBMIT'> </form></body></html>
a.pl:
#!/usr/local/bin/perl -w use CGI qw(:standard); my $name = undef; $name = param("name"); print "value = ",$name, "\n";
Please help. Thanks in advance.

Replies are listed 'Best First'.
Re: get parameter from html page
by shmem (Chancellor) on Dec 22, 2006 at 09:34 UTC
    Search for the -no_sticky (or -nosticky, the doc is inconsistent in that) pragma in CGI.

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: get parameter from html page
by SFLEX (Chaplain) on Dec 22, 2006 at 12:57 UTC
    Maybe the reason you can not see the stuff in "a.pl" is because you may need to use "print "Content-type: text/html\n\n";" before you print.
    Example:
    #!/usr/local/bin/perl -w use CGI qw(:standard); #my $name = undef; # is ok, but you'll get a warning if $name is blank +. my $name = param("name") || ''; # better for warn! print "Content-type: text/html\n\n"; # Setup the header for the browse +r print "value = ",$name, "\n";

    Once you Get your code to work. I want you to remember to check the param() inputs before you print them, if its going to be used in a public web page!
    As your "a.pl" sits now anyone could inject HTML and Javascript codes. that is a security risk if your going to let people you dont trust use the script.

    Here is an Example of how to secure your param():
    print "Content-type: text/html\n\n"; # Setup the header for the browse +r my $name = param("name") || ''; # Allow only numbers, letters and _ if ($name && $name !~ m/^[0-9A-Za-z_]+$/i) { print 'Error: Bad input Format'; exit; # Stop script }

    If the code needs a number and no letters just check for numbers in that param().

    Good Luck!

      Why not just use encodeHTML($name) instead (or in addition, if you allowed &, <, or >).
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.