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

I am writing a program to load and display multiple forms and to support cgi->save(FILE)'ing and loading form data.

Each form is written in HTML and stored in a text file. The main cgi loads the text file and sticks it in an HTML template and saves data to a filehandle on submit. To view and edit the form data, I have a second CGI which is called with a GET filename parameter.

However, when I do

$query = new CGI(FILEHANDLE)

and then load and display the form, the saved data doesn't make its presence known. I'm assuming that this is because my form HTML doesn't get associated with the $query since it is just text.

1 - Is this not working for the reason I think it's not working?
2 - If I construct the form using CGI $query->startform... will the saved state restore properly?
3 - if I do #2 how could I (or is there a module) to convert HTML into perl? 4 - if I do #3, how will I tell perl to load the form file and then process the commands in it (since I still want to have the option of loading many different forms)?

I'm sorry if this sounds complicated, I'm really tired and having trouble thinking straight. Any advice, direct or indirect is greatly appreciated.

Replies are listed 'Best First'.
Re: new CGI(FILEHANDLE)
by chromatic (Archbishop) on Aug 06, 2004 at 21:41 UTC

    The question confuses me, but here's an answer based on what I think you're asking in question #3.

    The CGI module (and pretty much all CGI-capable programs) don't read HTML forms. Web clients send HTTP data that include a URI which may have a query string or form-data with various chunks for each parameter.

    If the filehandle reads from an HTML file, it won't work at all. If it reads from a file that contains well-formatted form-data as a web browser would post to a web server, it will work better.

    If you know all this and this isn't your question, could you explain further what you're trying to do, not how you're trying to do it? That'll make it easier to suggest other ways to accomplish the same thing.

      I knew that wouldn't come out clear :)

      The form data is saved via $query->save(FILEHANDLE).

      Then I load it with a 'view.cgi' script using $query = new CGI(FILEHANDLE).

      However, the actual form tags are not generated with perl, they are flat HTML (stored in an external file). When I load view.cgi, it opens and displays the flat HTML form, but doesn't import the form data from FILEHANDLE.

      I am using external files for the form HTML because I want to be able to display multiple forms using the same scripts.

      My assumption was (I've just realized I could test this simply) that the form data wasn't showing up because the form was flat HTML and external - all the examples in the CGI.pm documentation construct the form inside the script using $query->createformelement(blah) construction.

      I'll welcome any suggestions on this, but I've had a chance to sleep a bit since I posted this, and I've come up with some other ideas I can try.