[development] Saving admin settings

Jeff Greenberg jeff at ayendesigns.com
Tue Jun 22 19:10:29 UTC 2010


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