[development] Saving admin settings
Jamie Holly
hovercrafter at earthlink.net
Tue Jun 22 19:15:50 UTC 2010
The only thing you are going to set on that form is 'active'. The
variable set is the same name as the last key in that form element, so
$form['fieldset']['key']['myvariable'] would set myvariable as the
variable name.
function myform_admin_settings() {
$form = array();
foreach ($foos as $foo) {
$form['myform'][$foo['id']] = array(
'#type' => 'fieldset',
'#title' => t($foo['id']),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['myform'][$foo['id']]['active'] = array(
'#type' => 'checkbox',
'#title' => t('Active'),
'#default_value' =>
variable_get('myform'.$foo['id']['active'],true),
);
}
return system_settings_form($form);
}
Jamie Holly
http://www.intoxination.net
http://www.hollyit.net
On 6/22/2010 3:10 PM, Jeff Greenberg wrote:
> On 6/22/2010 2:05 PM, John Fiala wrote:
> > Well, what's the $form like, is the main question. Remember that the
> > name of form elements is what gets stored in the variable table, and
> > that you need to set the #default_value of the form elements to
> > variable_get('name_of_form_element')
> >
> I minimized the form earlier to see if it was bad form structure, so
> it's a small paste. The problem is that in conjunction with the value
> always being the default value, the Variables table doesn't contain any
> field data from this form.
>
> function myform_admin_settings() {
> $form = array();
>
> foreach ($foos as $foo) {
> $form['myform'][$foo['id']] = array(
> '#type' => 'fieldset',
> '#title' => t($foo['id']),
> '#collapsible' => TRUE,
> '#collapsed' => TRUE,
> );
> $form['myform'][$foo['id']]['active'] = array(
> '#type' => 'checkbox',
> '#title' => t('Active'),
> '#default_value' =>
> variable_get('myform'.$foo['id']['active'],true),
> );
> }
> return system_settings_form($form);
>
> }
>
>
>
More information about the development
mailing list