By reedrob on
I'm using drupal 6.13 and trying to create my first theme - I started by copying garland.
I am wanting to add a lot of settings to the theme so I want them in collapsable fieldsets. The trouble I'm having is that I can't save/set the value for the fields within the fieldsets - I'm not having any trouble with the settings not contained within fieldsets.
Here is the relevant code...
function phptemplate_settings($saved_settings) {
/*
* The default values for the theme variables. Make sure $defaults exactly
* matches the $defaults in the template.php file.
*/
$defaults = array(
'garnad_happy' => 1,
);
// Merge the saved variables and their default values
$settings = array_merge($defaults, $saved_settings);
$form['garnad_happy'] = array(
'#type' => 'checkbox',
'#title' => t('Get happy'),
'#default_value' => $settings['garnad_happy'],
);
// Header Fieldset
$form['garnad_header'] = array(
'#type' => 'fieldset',
'#title' => t('Header'),
'#description' => t('Use these settings to change your header.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
// Header height
$form['garnad_header']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#description' => t('Specify the height as "auto" or in pixels.'),
'#default_value' => $settings['garnad_header']['height'],
);
// Return the additional form widgets
return $form;
}
Cheers,
Reed
Comments
Based on the looks of this
Based on the looks of this code, adding '#tree' => TRUE to the fieldset should make it work as your expecting. Unless you specify #tree the height field will get passed to the #submit function as ['height'].
--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.zivtech.com
It works with the change you
It works with the change you suggested.
Thank you Nick.
...
I do notice there is no default for height in the defaults array, I think you would do well to add one, not really sure that "height" is the best name for a theme setting, if you are going to add a lot I would suggest name spacing everything to keep it sane, eg
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.