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

My script process a html form, which post one parameter. But every time after I hit submit button, a window pops up asking for save/open/cancel. What's wrong?

Here are the form and the script:


<html> <head> <title>Fon</title> </head> <body> <form method="post" action="cgi-bin/" > <h2>Please enter phone</h2> <p><input type="text" name="fon" /></p> <p><input type="submit" name="submit" /></p> </form> </body> </html>


#!c:\perl\bin\perl print "Content type: text/html \n\n"; $input = <INPUT>; @qsinfo = split (/\=/, $input); $fon = @qsinfo [1]; open (OUT, ">fon.txt"); print OUT $fon, "\n"; close OUT; print "Your fon has been entered";

Edited 2003-07-02 by Ovid

Replies are listed 'Best First'.
Re: cgi response
by chromatic (Archbishop) on Jul 02, 2003 at 20:29 UTC

    I think you mean Content-type: text/html\n\n. Note that it has a hyphen. If you were to use the CGI module, you could simply use the header() method with no arguments:

    use CGI ':standard'; print header();

    You'll find you have more luck parsing params with than trying to read from INPUT which probably isn't even open.

Re: cgi response
by Tomte (Priest) on Jul 02, 2003 at 20:30 UTC

    Is this a stripped down version of the script, or what you intend to use?
    If the latter, then please: use CGI; use strict; use warnings; and call perl with the -T switch, be sure to Super Search the monastery and have a look at the Tutorials, not the least to check out is Ovids CGI-course.

    Is the script executable? is the http-server configured to allow script-execution in the cgi-bin directory relative to the scripts location? What is in the file, if you save it? I'd bet the script have to check


    Hlade's Law:

    If you have a difficult task, give it to a lazy person --
    they will find an easier way to do it.

Re: cgi response
by Coruscate (Sexton) on Jul 02, 2003 at 20:31 UTC

    You need to put a hyphen in the 'Content type' word(s) instead of a space. Also, you have a space at the end of the header. I doubt this is part of the problem, but possible. So print "Content type: text/html \n\n"; should say print "Content-type: text/html\n\n";. Oddly, mozilla processes "Content type: text/html \n\n" just fine.

    If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

Re: cgi response
by fglock (Vicar) on Jul 02, 2003 at 20:51 UTC

    Also, you will be better with '/cgi-bin' instead of './cgi-bin'

    <form method="post" action="/cgi-bin/" >
Re: cgi response
by gawatkins (Monsignor) on Jul 03, 2003 at 03:51 UTC

    Do other scripts with the pl extension work correctly? If not, check the application settings under the web site in IIS manager. These can be found by right clicking on the default web site, choosing properties, then clicking configuration at the bottom of the "Home Directory" tab. You should find that .pl is listed under mappings with an executable line something like C:\Perl\bin\perl.exe "%s" %s and Verbs limited to GET,POST. If it is not there, just add it in. If it is check for execute permissions on the cgi-bin folder under IIS manager and the file system


    Assumptions, that Windows/IIS Platform is being used and Perl.exe is located at c:\perl\bin\perl.exe since #!c:\perl\bin\perl

Re: cgi response
by Mago (Parson) on Jul 09, 2003 at 21:40 UTC
    #!/usr/bin/perl use warnings; use strict; use CGI qw( :standard ); our $query = new CGI; our $method = $query->param("op"); print $query->header; print $query->start_html(-title=>'Fon'); unless ($method) { print $query->start_form(-method=>"POST"); print $query->textfield(-name=>'fon'); print $query->hidden(-name=>'op', -default=>"01"); print $query->submit('submit','submit'); print $query->endform; } else { my $fon = $query->param("fon"); open (OUT, ">fon.txt"); print OUT $fon, "\n"; close OUT; print "Your fon has been entered"; } print $query->end_html;