The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.31 (Linux)
|
![]() |
[Kinda Solved] Problem updating checkbox value in sessions - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: [Kinda Solved] Problem updating checkbox value in sessions (/showthread.php?tid=604) |
[Kinda Solved] Problem updating checkbox value in sessions - coldrake - Mar 24th, 2010 Hi, I have a multi page form with MANY check boxes. I've set up the form so users can log in and out and update information using sessions. (method found here: http://forums.formtools.org/showthread.php?tid=225&highlight=continue+or+save+and+exit) The problem I'm running into is with the checkboxes. When the user logs back in, the form is populated from sessions and the check boxes are marked as "checked" like so Code: <input type="Checkbox" name="a1_strategic" value="Strategic" tabindex="1"<?php if($fields['a1_strategic'] =="Strategic"){echo " checked";} else {echo "";}?>> The initail value is saved and displayed fine, but if the user wants to edit the form and unchecks the checkbox, it doesn't clear the old value from the database when the form is submitted. I'm not sure if it's because an unchecked checkbox has no value to over ride the old value, or if it's because "checked" is written to the checkbox tag when the form is opened and, even if the checkbox is unchecked, it retains the "checked" in the code. Example: - First submission, user selects checkbox and value "X" is submitted to database. - User logs back in and unchecks the checkbox and submits the form. - If the user logs in a third time the original value of "X" is still there and the checkbox is checked. It should be showing as unchecked and no value in the session. This is the opening php for the form PHP Code: <?php I'm on a bit of a time crunch so any suggestions would be greatly appreciated. Thanks, Penny [Kinda solved] RE: Problem updating checkbox value in sessions - coldrake - Mar 25th, 2010 Well, in case anyone else runs into this problem. I did find a solution, though I expect it isn't the best one, it at least got the job done. Just before each checkbox, I added a hidden control with the same name as its corresponding checkbox and a value of " ". This at least managed to clear the old values out of the session. I'm sure I'll be coming across this issue in future projects so I would be very interested if there is a better solution. Penny |