I've written a module that allows users to alter the display of a Date/Time object by allowing them to change their timezone via a front-end block.
It does it's primary function properly, changes the time display as expected, however, what is supposed to happen is that once you pick a timezone, the page reloads, and the dropdown form will default to the timezone you selected. Except it doesn't, it stays on a single default value
The array is the #options list for the dropdown item, and the single item underneath is the #default_value key for that dropdown.
As you can see, the default value should be set to Australia/Melbourne, but in the dropdown it's not, it's set to America/Creston Mountain time.
I cannot figure out what's going wrong, have I done the default value code incorrectly or something?
EDIT
This is the code for the select element
$timezone = mymodule_timezone_get_user_timezone();
$options = variable_get('mymodule_timezone_select', system_time_zones());
$options = array_filter($options);
// doing a dpm($timezone) comes back with Australia/Melbourne
// doing a dpm($options) comes back with the arrow shown above
$form['timezone_select'] = array(
'#type' => 'select',
'#title' => '',
'#options' => $options,
'#default_value' => $timezone,
'#prefix' => t('<div class="description">Please select your timezone from the drop down box below and click update to convert your viewing times accordingly.</div>'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update') ,
);
And the code referenced in this snippet
function mymodule_timezone_get_user_timezone() {
$retrieved_timezone = session_cache_get('mymodule_timezone_user_timezone');
if (empty($retrieved_timezone)) {
$retrieved_timezone = drupal_get_user_timezone();
}
return $retrieved_timezone;
}
The variable for 'mymodule_timezone_select' is just from the default system_time_zones() but the admin has been given the option to delete ones they don't want the user to see (since they are several hundred options by default)
$timezone
somewhere in between.