in reply to CGI::Session Simple Example

I recently got bogged down with using HTML::Template and persisting form fields when an error occurred in form processing. What I ended up doing was just using CGI.pm for creating the form fields. Each field can be set a default value by using the -default named parameter. So in this case, I just set the -default to $sess->{'whatever'}, and of course, if key 'whatever' doesn't exist, it just gets undef, no harm, no foul.

There are other options for prefilling your forms as well. Check out HTML::FillInForm.

The other thing you can do to simplify your scripts is use something like CGI::Application to organize your data. You can use the prerun/postrun hooks to create and persist your sessions automatically, so when you get down to actually programming logic, you don't have to think about those housekeeping things anymore.

Replies are listed 'Best First'.
Re^2: CGI::Session Simple Example
by Anonymous Monk on Mar 14, 2006 at 21:06 UTC

    CGI::Application moves you more from managing individual scripts to a MVC framework. I would suggest that you head this way also.

    CGI::Application also has numerous plugins. There is only for CGI::Session which is alot easier to work with than CGI::Session directly, and there is another plugin for HTML::FillInForm as well.