[Pdx-pm] saving state with CGI.pm

John Springer john at digitalmx.com
Tue Nov 4 20:58:34 CST 2003

I'm having a problem using CGI.pm to save state.  Maybe I'm using the 
wrong tool??  Anyways...
I have users going through several forms to collect information, and 
I'm saving the state of the CGI object in a session file. But I want to 
keep a "running list" of all the data that has been set across all the 
forms, so the user can bounce back and forth without losing anything.  
I got it to work but it's awkward and took a lot of trial and error.
Here's what I'm doing:
1. create new cgi object with form values ($q= new CGI();)
2. open another CGI object from the previously saved state. ($p= new 
3. add all the variables from $p that aren't in $q to $q.
	 if($var is in $p but not in $q) {
		$q->param($var,$val); #sets $var to $val in $q.
4. Save the state of $new back to the file.   $q->save(FILEHANDLE);

One of the difficulties is that the ->param($var,$val) notation fails 
if $val is null.  Also if $var was
previously set but the current form clears it, it needs to get cleared. 
  The if() in step 3 got rather complicated.  I run through a sorted 
list of variables in $q and compare to a sorted list of variables in $p 
and pass only the vars in p but not in q.

I have a feeling I've turned something simple into something really 
complicated.  Can anyone put me on the path of righteousness?

   John Springer
   Somewhere in Portland
   Where it's probably raining.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 1517 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/pdx-pm-list/attachments/20031104/32ee309d/attachment.bin

More information about the Pdx-pm-list mailing list