I have a single Perl script with a dispatcher which I want to display either an HTML FORM or the plain text results.
FORM displays properly. Clicking Submit results in a download dialog box, instead of just displaying the plain text results (in a browser window). Using print "Content-type: text/plain\n\n"; doesn't work. How can I just display plain text (which contains HTML) but with NO HTML interpretation?
FORM displays properly. Clicking Submit results in a download dialog box, instead of just displaying the plain text results (in a browser window). Using print "Content-type: text/plain\n\n"; doesn't work. How can I just display plain text (which contains HTML) but with NO HTML interpretation?
Code:
#!/usr/bin/perl
#
# Test text/plain
#
use CGI qw/:standard/;
use strict; # we need every bit of help we can get
# Dispatcher
# Get operation
my $operation = param('oP'); # DISPLAYLISTING or DISPLAYFORM
if ($operation eq "") {
$operation = "DISPLAYFORM"; # default
}
if ($operation eq "DISPLAYFORM") {
displayForm();
} elsif ($operation eq "DISPLAYLISTING") {
displayListing();
} else {
die "INTERNAL ERROR: $operation is an unknown operation";
}
exit(0);
sub displayForm {
my $size=80;
print "Content-type: text/html\n\n";
print <<EOM;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Display Form</title>
</head>
<h1 align="center">Listing Generator</h1>
<table border=0>
<form action="" method="POST">
<tr>
<td> </td><td><input name="oP" type="hidden" value="DISPLAYLISTING"></td>
</tr>
<tr>
<td>Title</td><td><input name="title" type="text" value="Jar" size=80></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Submit"></td>
</tr>
</form>
</table>
</body>
</html>
EOM
}
sub displayListing {
print "Content-type: text/plain\n\n";
my $title=param('title');
print "<h1>Title: $title</h1>\n";
}
1