generating html form on the fly

Discussion in 'Perl Misc' started by ll, Oct 22, 2007.

  1. ll

    ll Guest

    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;
    }
     
    ll, Oct 22, 2007
    #1
    1. Advertising

  2. ll

    Guest

    ll <> wrote:
    > 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.
     
    , Oct 23, 2007
    #2
    1. Advertising

  3. ll

    J. Gleixner Guest

    ll wrote:
    > 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/
     
    J. Gleixner, Oct 23, 2007
    #3
  4. ll <> wrote:

    > 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 q(<form method="post" action="uploader_ee.cgi">);


    > print "<table border=\"1\">\n";


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



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


    $fitem_pathname = "$list_dir/$fitem";


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad McClellan, Oct 23, 2007
    #4
  5. ll

    Ron Bergin Guest

    On Oct 22, 8:58 pm, Glenn Jackman <> wrote:
    > At 2007-10-22 09:19PM, "Tad McClellan" wrote:
    >
    > > ll <> wrote:
    > > > 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 q(<form method="post" action="uploader_ee.cgi">);

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

    or print $cgi->start_form(-action=>'uploader_ee.cgi');
    >
    > > > print "<table border=\"1\">\n";

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

    >
    > 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.
     
    Ron Bergin, Oct 23, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. smrtalec
    Replies:
    0
    Views:
    460
    smrtalec
    Jan 26, 2004
  2. genc_ymeri
    Replies:
    3
    Views:
    500
    JDP@Work
    Mar 14, 2006
  3. D. Alvarado
    Replies:
    1
    Views:
    325
    Andrew Thompson
    Oct 12, 2004
  4. ll

    generating form on the fly

    ll, May 5, 2008, in forum: ASP General
    Replies:
    1
    Views:
    109
  5. Brian

    Fly outmenu on the fly

    Brian, Apr 8, 2005, in forum: Javascript
    Replies:
    0
    Views:
    110
    Brian
    Apr 8, 2005
Loading...

Share This Page