generating html form on the fly

L

ll

I'm currently working with a cgi script which can upload, view, or
delete files in a given directory. The delete section is rather
cumbersome, in that the user has to type in the file name and password
and then hit the delete button.
I've created an html form in the view section that puts checkboxes
next to each file listed. Here's the code I have (below). I'm
getting an error that says that the 'post' command isn't recognized.
Thanks for any help,
Louis

------------------------------------------------
sub listfilenames {
&check_url_referer;

if ($in{'pwd'} ne $superpwd) {
&error_password;
}
if (!$in{'filedirname'}) {
&error_no_upload_directory;
}
$list_dir = "$parent_dir$in{'filedirname'}";
if (opendir(DIR,"$list_dir") == 1) {
@files = readdir(DIR);
closedir(DIR);
}
else {
&error_cannot_open_dir;
}

&set_content_type;
print "<html><body><center><font size=+1 color=
\"FF0000\"><b>Listing of Filenames</b></font></center><p>\n";
print "<b>The following filenames are found in directory
\"$in{'filedirname'}\":<br>\n";
print "<form method=\"post\" action=\"uploader_ee.cgi\">";
print "<table border=\"1\">\n";
$count = 0;
foreach $fitem (@files) {
$fitem_pathname = "$list_dir" . "/" . "$fitem";
if (-e $fitem_pathname) {
if (-d $fitem_pathname) {next;}
$count++;
print "<tr><td><input type=\"checkbox\" VALUE=$fitem></
input></td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$fitem </td><td>- <a href=
\"$parent_url$in{'filedirname'}\/$fitem\" target=\"_blank\">View this
file</a><br></td>\n";
}
}
if ($count == 0) {
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sorry, nothing found!!<br>
\n";
}
print "</table>\n";
print "<input type=\"submit\" value=\"Delete File\">\n";
print "</form>\n";
print "</b><p>\n";
print "</html>\n";
&listfilenames_ok;
}
 
X

xhoster

ll said:
I'm currently working with a cgi script which can upload, view, or
delete files in a given directory. The delete section is rather
cumbersome, in that the user has to type in the file name and password
and then hit the delete button.
I've created an html form in the view section that puts checkboxes
next to each file listed. Here's the code I have (below). I'm
getting an error that says that the 'post' command isn't recognized.

Where exactly are you getting this error? The code you posted looks like
it merely creates the form html (poorly). The error sounds like it coming
from something that processes a form submission. But you could try
changing the "post" to a "get" in the "<form...>" element.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
J

J. Gleixner

ll said:
I'm currently working with a cgi script which can upload, view, or
delete files in a given directory. The delete section is rather
cumbersome, in that the user has to type in the file name and password
and then hit the delete button.

You have to be very careful about this.

I've created an html form in the view section that puts checkboxes
next to each file listed. Here's the code I have (below). I'm
getting an error that says that the 'post' command isn't recognized.

Post a short and complete example that we can run that shows the
error and where it's coming from. This code is quite poor and
shows many problems, none of which have to do with "'post'
command isn't recognized".

Thanks for any help,

perldoc -f qq
perldoc -q "What's the difference between calling a function as &foo and
foo()"

perldoc CGI

Use a class to help you separate your HTML and your perl.

perldoc HTML::Template
perldoc Template::Toolkit

If neither are on your system, take a look at CPAN: http://search.cpan.org/
 
T

Tad McClellan

ll said:
I'm
getting an error that says that the 'post' command isn't recognized.


Please do not paraphrase messages.

You should post the exact text of the message.

&check_url_referer;


You should not call subroutines that way unless you know what
special treatment that way enables, and you really do want
that special treatment.

It is safer to call subroutions this way instead:

check_url_referer();

if (!$in{'filedirname'}) {


What if the name of the directory should happen to be "0" ?

(your program will call the error routine rather than doing the right thing)

If you want to test that $in{'filedirname'} actually contains the
name of a directory, then test that it actually contains the name
of a directory:

if ( ! -d $in{filedirname} ) {
or
unless ( -d $in{filedirname} ) { # better

if (opendir(DIR,"$list_dir") == 1) {


perldoc -q vars

What’s wrong with always quoting "$vars"?

It is only a happy accident that today's opendir() returns one
on success.

It is specified to return true, and may change to any other true
value at any release, so you should check for truth instead:

if ( opendir DIR, $list_dir ) {

print "<form method=\"post\" action=\"uploader_ee.cgi\">";


Yuck. Write is so that you can read it:

print '<form method="post" action="uploader_ee.cgi">';
or
print "<table border=\"1\">\n";

print qq(<table border="1">\n);


$fitem_pathname = "$list_dir" . "/" . "$fitem";

$fitem_pathname = "$list_dir/$fitem";
 
R

Ron Bergin

or print "<form method='post' action='uploader_ee.cgi'>";
or print $cgi->start_form(-action=>'uploader_ee.cgi');
or print "<table border='1'>\n";
or print $cgi->start_table({border=>1});
As you can see, I prefer CGI's OO interface, but the functional
interface is fine, however, it doesn't support all of the features
that the OO interface supports.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top