NetTalk Central

Author Topic: Check box and cookies problem  (Read 3985 times)

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Check box and cookies problem
« on: December 02, 2008, 05:05:58 PM »
Hi,

I have a problem using cookies to store user choices for a check box between sessions.   Cookies work fine with radio buttons, lookup fields, but not cookies.   Once a user has checked the box (True) and  the cookie has been saved, the cookie cannot be saved as False again.   Further the old True value is saved to table which in this case is an In-Memory table that collects several parameters for controlling a Browse page.

I have confirmed that the table value and associated SessionValue,  are changed to False when the user unchecks the box but before the table is saved or or the cookie set they are changed back to True.  I tried manually doing SetValue to 0 as well but without success.

I also confirmed that the problem was not just saving 0 as a cookie value.  A radio button option of 0 works fine.  It is limited to the check box.

Any insight would be greatly appreciated.   Thanks.

CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Check box and cookies problem
« Reply #1 on: December 02, 2008, 05:08:17 PM »
Sorry.  Forgot to include I am using 4.31 PR18.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Check box and cookies problem
« Reply #2 on: December 02, 2008, 11:24:33 PM »
Hi Casey,

>> I have a problem using cookies to store user choices for a check box between sessions.

ok, using cookies for this is probably the wrong approach. Now it might depend on your very specific circumstances, but generally you should store user settings in a table on the server, and then fetch them based on the user's login.

Storing the setting as a cookie is ineffective because the user may obviously change machine. Also other users using the same machine will then share the settings. Last but not least, _all_ the cookies for a site are transmitted with _every_ request. So you start by storing one thing, and it rapidly escalates.

If you don't have a login then you can store one "identifier" cookie on the user machine, which then maps to a record in your "settings" table. Then you can add multiple settings to the table, without adding more cookies.

Now to the specifics. The issue under the skin is that the way checkboxes work is complicated. NetTalk hides so much of this stuff from you, but checkboxes "send a value if 1" and "do not exist if 0". So in the latter case the cookie overrides the "non existent value".

Incidentally if you o make cookies they should _not_ have the same name as the screen fields (unless you really know what's happening.) The potential for there to be a clash is very probable.

cheers
Bruce


CaseyR

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
    • Email
Re: Check box and cookies problem
« Reply #3 on: December 05, 2008, 04:48:28 PM »
Thank you very much for the comprehensive reply, Bruce

I will look to use Unchecked = 1, Checked = 2 in the future

Yes, I can move to a separate table for intersession user choices.