7

我正在使用 drupal form api 并使用复选框。我在默认检查值中遇到问题。以下是代码片段...

$result = db_query("SELECT nid, filepath FROM {content_type_brand}, {files} WHERE content_type_brand.field_brand_image_fid
= files.fid");
        $items = array();
        while ($r = db_fetch_array($result)) {
                array_push($items, $r);
        }
        $options = array();
        foreach( $items as $i ) {
            $imagePath = base_path().$i['filepath'];
            $options[$i['nid']] = '<img src="'.$imagePath.'"></img>';
        }
        $form['favorite_brands'] = array (
            '#type' => 'fieldset',
            '#title' => t('Favorite Brands'),
            //'#weight' => 5,
            '#collapsible' => TRUE,
            '#collapsed' => FALSE,
        );
         $form['favorite_brands']['brands_options']
= array(
            '#type' => 'checkboxes',
            '#options' => $options,
            '#default_value' => $options_checked,// $options_checked is an array similar to $options but having elements which need to be checked by default...
            '#multicolumn' => array('width' => 3)
        );

但默认情况下不检查值...任何人都可以帮助我缺少什么?

谢谢

4

1 回答 1

7

您的 $options_checked 数组不应与您的 $options 数组采用相同的格式。您的 $options 数组包含 nid => img 标签对。您的 $options_checked 数组应仅包含默认情况下应检查的选项的 nid 值:

$options_checked = array(8,17);
于 2011-04-14T02:00:06.550 回答