Lately, it seems that I'm stumped by what turns out to be 'weak eyes.' Here's another. I have a callback to the function in a module that provides the admin settings form for the module. The form appears just fine, and functions correctly. At the end of my form definition I have the obligatory return system_settings_form($form); The issue is that none of the form data is stored. The form is generic...no submit handler specified. Jeff
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') On Tue, Jun 22, 2010 at 12:02 PM, Jeff Greenberg <jeff@ayendesigns.com> wrote:
Lately, it seems that I'm stumped by what turns out to be 'weak eyes.' Here's another. I have a callback to the function in a module that provides the admin settings form for the module.
The form appears just fine, and functions correctly. At the end of my form definition I have the obligatory
return system_settings_form($form);
The issue is that none of the form data is stored. The form is generic...no submit handler specified.
Jeff
-- John Fiala www.jcfiala.net
Also make sure you don't have any #tree=>true in that form. That can play havoc with system settings forms. Jamie Holly http://www.intoxination.net http://www.hollyit.net 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')
On Tue, Jun 22, 2010 at 12:02 PM, Jeff Greenberg<jeff@ayendesigns.com> wrote:
Lately, it seems that I'm stumped by what turns out to be 'weak eyes.' Here's another. I have a callback to the function in a module that provides the admin settings form for the module.
The form appears just fine, and functions correctly. At the end of my form definition I have the obligatory
return system_settings_form($form);
The issue is that none of the form data is stored. The form is generic...no submit handler specified.
Jeff
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); }
Well, my initial idea would be to check the variables table to see if anything's been written to 'active'. By default, it's going to use the right-most name in the form structure to refer to the fields. I think you might want to set $form['#tree'] = TRUE;
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);
}
-- John Fiala www.jcfiala.net
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);
}
Yup, thanks! Sorry to bother you both with that. I think one more blinding flash of the obvious this week and I may suffer pupil trauma :-) Jeff
participants (3)
-
Jamie Holly -
Jeff Greenberg -
John Fiala