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

I have a script called a.cgi - which prints out a form which includes the normal submit and reset buttons at the end. The target for this form is b.cgi. To start with when the submit button was clicked b.cgi would take over and the form data was printed out ala html. But as a result of clicking the submit button i want to print out a text doc. THerefore i deleted print header(), start_html("some script"), and at the end end_html(), and replaced them with print header(-type=>'text/plain'). But now when I click on submit the browser begins to download b.cgi instead of recieving the text as I expected. But if i just enter http://baz.perlmonk.org/cgi-bin/b.cgi into the address window the script acts as i expected - outputing text in the browser window. THerefore the problem is only happening when the submit button calls b.cgi and when b.cgi prints in text context instead of html, another difference is that hitting submit posts to b.cgi. Whats going on, anyone?
Below is the piece of code used to call b.cgi( a.cgi and b.cgi are in the same directory)
print startform(-action=>'b.cgi',-target=>'_top'),table(Tr(\@table_con +t)),submit(-name=>'Submit'),reset(-name=>'Reset'),end_form;
...and everything worked perfect before i changed the header function etc, as outlined above.

Replies are listed 'Best First'.
Re: Problem calling a script which outputs plain text
by Fastolfe (Vicar) on Nov 17, 2001 at 07:18 UTC
    This is a defect of Internet Explorer. I would complain to Microsoft about this, but I think they've stated pretty clearly that they have no intention of fixing the problem.

    The thing is, text/plain is too generic for IE to like, so it assumes the web server doesn't quite know what it's talking about issuing a MIME type like that and attempts to do its own thing to figure out what the content actually is. Since it fails to find any thing special about it, but the URL has a .cgi extension, it shrugs its shoulders and tries to download it as a .cgi file. Since it has no idea what a .cgi file is, it asks you what you want to do with it.

    The solution would be for your script to posts its results to, say, b.cgi/results.txt instead. The /results.txt will be passed to your script via the 'path_info' method but will otherwise be ignored (your script will behave as it did before). IE will see the "filename" and say, "Hey, it really is a text file!" and display it as you expect.

      Thanxs Fastolfe, i actually managed to get it working just b4 i read ur post, i just used method get instead of post. Lucky using get is an option as im not sending much form data.
Re: Problem calling a script which outputs plain text
by Baz (Friar) on Nov 17, 2001 at 05:16 UTC
    i downloaded b.cgi after clicking submit and its actually the text i expected to be displayed in the browser???