Could someone explain the proper way to code forms in 4.7? Some of the modules, after upgrading, use legacy form generation code, that doesn't seem to work even after enabling the Legacy module. I can't make heads or tails out of the new code.
Specifically, I'm trying to get a checkbox. I have the following code, which almost works, but doesn't actually set the value as I need it:
function image_tab_settings() {
// Global Image Display Settings
$form['imageDisplay'] = array('#type' => 'fieldset', '#title' => t('Global Image Display Settings'));
$form['imageDisplay']['image_tab_globally_display_images'] = array('#type' => 'checkbox',
'#title' => t('Display images globally'),
'#return_value' => TRUE,
'#default_value' => variable_get('image_tab_globally_display_images', TRUE),
'#description' => t('If checked, images may be displayed with content, although some types of content may override this setting. When not checked, no images associated with any content will ever be displayed automatically.')
);
return $form;
}
I borrowed this from the new user module (line 1167). I'm trying to set the variable 'image_tab_globally_display_images'. Instead, it always returns a check, even if it's not checked.
The user module uses '#default_value', but looking at the API for theme_checkbox($element), it looks like perhaps I should use '#value' instead. However, that doesn't work either.
I've looked for some documentation about the new way that Drupal will handle forms, but haven't found any yet. Perhaps someone could point me in the right direction.
Thanks,
Aaron
Culture Fix Web Identity & Design
Digital Folk Art (my blog)