I've been modifying a trivia game (originally written by someone else) for a few weeks. They used CGI.pm extensively, which irritates me to no end, but I wanted to work with it.
I wanted to keep track of which questions had not been asked yet. So, I decided to place this list of unasked questions in a hidden field (rather than a cookie, or a file on the server.) To my surprise, this list remained the same through every post, instead of updating as I had intended.
After reviewing the code several times, becoming increasingly frustrated each time, I determined my code was fine. So, I read the freaking manual. I had no idea that state was maintained with CGI.pm when you use the HTML generating functions to print out fields. And even when I first read that state was maintained, I didn't believe that it applied to my code.
So here are my questions:
As a note to anyone else that experiences this problem, there are two ways of eleviating the situation.
The first is to not use the CGI.pm function to create the field that has irritatingly consistent data. For example: the script was using hidden() to create a hidden field, and I simply used a print statement and wrote the HTML myself.
The second is to use delete() to delete the problematic field's data before you create the field again (e.g. $query->delete('hidden_field')).
Another way of fixing this would be to turn state-maintenance off, if possible.
# Dross, Professional Dullard
Edited 2001-08-04 by Ovid
In reply to CGI.pm: How to Stop Maintaining State by Dross
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |