I haven't actually used CGI::Session, so I may be off-base here. But from reading the description, it appears that statements like:
$Session->param(-name=>'age', -value=>$age, -force=>1);
and
$Session->param(-name=>'name', -value=>$name, -force=>1);
won't do what you expect.
I'm basing this on the descriptiong of save_param($cgi) at the
CPAN site:
This method is the opposite of load_param(). It saves all the parameters in your CGI environment to your Session's parameters. For example, you might want all the information that user supplied in a form in your website to be saved into the session object. Again, remember to pass CGI object as the first and the only argument.
Example:
$Session->save_param($cgi);
So I think first you have to get your CGI.pm variables right. Rather than the "$Session" statements you were using, you could try:
print $cgi->hidden(-name=>'name', -value=>"$name");
print $cgi->hidden(-name=>'age', -value=>"$age", -force=>'1');
immediately before the end_form and submit statements. This saves the name and age variables (with the force='1' making the incremented age variable replace the old "sticky" parameter).
Then at the top of the script, which you will now be re-entering after executing the "submit" statement, but this time with the CGI parameters "right" and actually available to the script, put the
$Session->save_param($cgi);
statement. (If you don't get the CGI parameter variable saved, in this case as hidden variable, as you found they will be lost. I suspect the $Session statements didn't save them either.)
Often in this case you might go away, using the cookie value for reentry later. Or you can recall it as your code now works. But until the values are saved in the CGI.pm space, you apparently can't save them one at a time into the CGI::Session database.
Live in the moment.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.