drupal形式api复选框

时间:2011-02-10 08:03:56

标签: drupal-6 form-api

我正在使用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)
        );

但默认情况下不会检查值...任何人都可以帮助我找不到的东西吗?

由于

1 个答案:

答案 0 :(得分:7)

您的$ options_checked数组的格式不应与$ options数组相同。您的$ options数组包含nid =&gt; img标签对。您的$ options_checked数组应该只包含默认情况下应检查的选项的nid值:

$options_checked = array(8,17);