rondog Posted September 25, 2010 Share Posted September 25, 2010 I have an array of fields: $fields = array( "cfg_change_date" => "Configuration Change Date", "system_name" => "System Name", "system_manf" => "System Manufacturer", "system_model_no" => "System Model Number", "system_serial_no" => "System Serial Number", "system_board_part_no" => "System Board Part Number", "system_board_serial_no" => "System Board Serial Number", "asset_tag" => "Asset Tag", "sla_code" => "SLA Code", "category" => "Category", "os_version" => "OS Version", "os_upgraded" => "OS Upgraded", "bios_version" => "BIOS Version", "bios_upgraded" => "BIOS Upgraded", "ilom_version" => "ILOM Version", "ilom_ip" => "ILOM IP Address", "ilom_updated" => "ILOM Updated", "rack_id" => "Rack ID", "rack_location_id" => "Rack Location ID", "tech_id" => "Tech ID", "warranty" => "Warranty" ); I have them all outputted as checkboxes right now in a form. When the user hits save, I want the checked ones to be stored in a single cookie and then later referenced so it remember what the user wants to query from the DB. The thing I cant figure out is how to do this dynamically rather than checking if each one is checked. Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/ Share on other sites More sharing options...
trq Posted September 25, 2010 Share Posted September 25, 2010 The thing I cant figure out is how to do this dynamically rather than checking if each one is checked. Only the checked fields will apear within the post array when the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115378 Share on other sites More sharing options...
rondog Posted September 25, 2010 Author Share Posted September 25, 2010 ah ok I gotcha..I just did this and it it showing the checked ones if (isset($_POST['saveFieldSelections'])) { $checks = $_POST['checkboxes']; if (isset($checks)) { while (list ($key,$val) = @each ($checks)) { echo "$val,"; } } } Now my question is, should I just convert this to a string and store a long string? I would then explode() when I retrieved them. Does that sound about right? Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115381 Share on other sites More sharing options...
rondog Posted September 25, 2010 Author Share Posted September 25, 2010 Ok I went ahead and used that method i described above and its kinda working. When I set my cookie, it seems the page doesn't recognize it til I refresh the page again. Like I have 3 boxed checked and check 2 more. After I hit the save, button the page does its thing, but I still only see 3 checked. If I refresh the page, they show all checked. Why is this? Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115387 Share on other sites More sharing options...
trq Posted September 25, 2010 Share Posted September 25, 2010 You obviously need to refresh the page after the cookie is saved in order for the information on the page to be updated. You'll need to do a redirect (to the same page) after you save the cookie. Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115388 Share on other sites More sharing options...
rondog Posted September 25, 2010 Author Share Posted September 25, 2010 Ok I was gonna do that as a 'work around'. It just sounds like I may have been doing something wrong Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115495 Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2010 Share Posted September 25, 2010 No, it's just that cookie data is not available until the next page load, hence the need for a redirect before you can use it. That's normal operation for cookies. Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115497 Share on other sites More sharing options...
rondog Posted September 25, 2010 Author Share Posted September 25, 2010 No, it's just that cookie data is not available until the next page load, hence the need for a redirect before you can use it. That's normal operation for cookies. That's good to know. This is my first experience using cookies. Thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/214334-cookie-array/#findComment-1115522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.