如何在drupal 7中的select元素(来自API)中显示小图像

时间:2011-08-10 13:50:38

标签: image forms api drupal-7

我想知道如何在Drupal表单API中的select元素中显示图像。

以下代码显示了带有两个文本格式选项的简单选择:“ - 34 - ”,“ - 36-”。

    $sizes = array_combine(array(34, 36), array("-34-", "-36-")); 
    $form['editplayer']['clothes_size_female']['clothes'] = array( 
        '#type' => 'select', 
        '#default_value' => 34, 
        '#options' => $sizes,  
    );  

我尝试将路径放到图像中,但它将其视为字符串。 $sizes = array_combine(array(34, 36), array("http://localhost/drupal/renderImage.php?user_id=34", "http://localhost/drupal/renderImage.php?user_id=36"));

1 个答案:

答案 0 :(得分:1)

使用股票HTML选择框元素没有一种支持良好的方法。虽然有解决方案可以使用JavaScript:

http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx

您必须编写自定义Drupal表单元素,但要使用Form API。