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

Hello fellow monks:

I have just gotten some feedback from the user about a perl/cgi form I made for them. The problem is at the end of the form (the submission page) they want to see all the information that they entered the whole time. Right now it just displays the current form they filled out so if they went back and refilled out something else the submission page would just show the most recent form they filled out. Not a collection of the previous form and the current one they just did.

I guess I need to save data in a file or make a temporaray DB table with a transaction id or something so I can save all the data on one particular transaction for the whole form entry process. Because right now I'm just passsing the form data with hidden html tags so I can only build a table at the end of the form for the most recent form they filled out. It's not a collection of the forms for a particular transaction.

My question is what is the best way to do this. Just pass all the data to a file or make a DB table. I know I can't use hidden tags anymore to accomplish this task so I need a more efficent idea

Thanks,

new_2_perl

Edit by ar0n

Replies are listed 'Best First'.
Re: encoding/decoding perm storage
by Zaxo (Archbishop) on Aug 01, 2001 at 13:59 UTC

    If I understand you correctly, you are accumulating queries from multiple forms as hidden fields. That is a perfectly good way to maintain state.

    To display data from previous forms, you only need to use the CGI::param() methods to extract the field values. Add static text to taste and serve. To display material from the current form before POST, you will need to provide some clientside scripting.

    After Compline,
    Zaxo

Re: encoding/decoding perm storage
by trantor (Chaplain) on Aug 01, 2001 at 15:40 UTC

    If you can't use hidden tags anymore but you still want the browser to keep all the information, you can resort to cookies. Check this if you're unfamiliar with them, paying particular attention the limitations in terms of number of cookies and size. They can matter if you carry lots of forms data.

    There are many modules on CPAN helping you handling cookies, you definitely know CGI.pm as it's in the standard distribution, but I also like Apache::ASP.

    Also keep in mind security implications of having the browser reporting the information (via cookies or hidden tags) as it can be easily forged and/or eavesdropped.

    If you want to keep the information on the server side, you have many options. Apache::Session or Apache::ASP's $Session variable might be a good starting point.

    If you want to write on your own files, you have to be very careful when yuo choose a file name, you decide whether a file name is shared among all sessions or it belongs to a single session, you have to thing about cleaning it up when a session ends (or after a certain timeout).

    Many of these considerations (especially session cleanup, less problem with concurrent access) apply to database tables too. Perl has the wonderful DBI interface in this case. If running under Apache, Apache::DBI may help improving performance.

    To keep it short, considering that you are a beginner, I'd suggest to use Apache::Session (or similar) or a cookie approach.

    -- TMTOWTDI