By jdevries on
Hi,
I'm having a go at the very first module that I'm creating. However, I'm running into a bit of an issue that I can't seem to figure out. The code below is part of the code used to display the settings on the administration pages. It all appears to work perfectly: the form is displayed and each checkbox has a unique return value and I can successfully submit the form if all checkboxes are empty.
However, as soon as I select any one or more checkboxes, I get a "An illegal choice has been detected. Please contact the site administrator." error. Why?
// check to see if imagecache module exists, to unluck more options
// only needs to be done once, because we can then just count the preset array
$presets = array();
if (module_exists('imagecache')) {
$presets = array_merge(array(t('original')), _imagecodes_get_subarray_elements(imagecache_presets(), 'presetname'));
} else {
$presets = array(t('original'));
}
$form['fieldset_imagecodes'] = array (
'#type' => 'fieldset',
'#title' => 'Image codes',
'#collapsible' => TRUE,
'#collapsed' => FALSE
);
foreach ($presets as $preset) {
$form['fieldset_imagecodes']['fieldset_preset_'.$preset] = array (
'#type' => 'fieldset',
'#title' => $preset,
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
// create image codes options checkboxes
$options['code_'.$preset.'_direct'] = t('Direct link');
$options['code_'.$preset.'_html'] = t('Wrap the %preset image in HTML tags', array('%preset' => $preset));
$options['code_'.$preset.'_bbcode'] = t('Wrap the %preset image in BBCode tags', array('%preset' => $preset));
$options['code_'.$preset.'_html_link_original'] = t('Wrap the %preset image in HTML tags, linking to the original image', array('%preset' => $preset));
$options['code_'.$preset.'_bbcode_link_original'] = t('Wrap the %preset image in BBCode tags, linking to the original image', array('%preset' => $preset));
$options['code_'.$preset.'_html_link_node'] = t('Wrap the %preset image in HTML tags, linking to the node', array('%preset' => $preset));
$options['code_'.$preset.'_bbcode_link_node'] = t('Wrap the %preset image in BBCode tags, linking to the node', array('%preset' => $preset));
if (count($presets) > 1) {
$options['code_'.$preset.'_html_link_original_thumb'] = t('Wrap the thumbnail image in HTML tags, linking to the %preset image', array('%preset' => $preset));
$options['code_'.$preset.'_bbcode_link_original_thumb'] = t('Wrap the thumbnail image in BBCode tags, linking to the %preset image', array('%preset' => $preset));
}
$form['fieldset_imagecodes']['fieldset_preset_'.$preset]['preset_selection'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_option' => variable_get('preset_selection', 0)
);
unset($options);
} //foreach ($presets as $preset)
For the sake of completeness, here is the _imagecodes_get_subarray_elements function as well:
/**
* Create a one-dimensional array for subarray elements of a two-dimensional array
*/
function _imagecodes_get_subarray_elements($array_name, $key_name) {
foreach ($array_name as $row) {
$return_array[] = $row[$key_name];
}
return $return_array;
}
Thanks in advance.