in reply to Creating persistent table with CGI.pm

CGI.pm enables you to store a query object's state to a file for later retrieval. The use of this feature should solve your problem.

To store a query object to a file you should use CGI.pm's object-oriented style. Create a uniquely-named query object for each form you submit. Thus at the top of each form handler you might say something like: $myQueryObject = new CGI;.

You will need to find out the name of the user under which your CGI script runs. Let us say that this user is named 'web'. Then, at the end of your form handler open up a filehandle to a directory in which 'web' has read/write privileges. Then save the query object using that filehandle, e.g. $myQueryObject->save(FILEHANDLE).

If in a subsequent form handler you need to retrieve a value from a previous form, simply create a new query object from a filehandle that points to the file where you saved the previous query object, as in: $myPreviousQuery = new CGI(INPUTFILE);.

Finally, you can retrieve any parameter from the previous query object by using CGI.pm's param() function.

I have found that when opening up a previous query object it is better to use a reference to the file handle, e.g. $myPreviousQuery = new CGI(\*INPUTFILE);.

  • Comment on Re: Creating persistent table with CGI.pm