2011-08-07 31 views
2

我試圖讓一個廣播框在它旁邊顯示一個圖片,當用drupal 7 form api選中時,我不知道從哪裏開始。我會很感激一些help.Thank你Drupal 7 form api radio box /複選框圖片選擇

這是我使用的代碼:我只是想通了這一點

<?php 


function test_module_menu() { 
    $items = array(); 
    $items['test_module/form'] = array(
    'title' => t('Test'), 
    'page callback' => 'test_module_form', 
    'access arguments' => array('access content'), 
    'description' => t('Test'), 
    'type' => MENU_CALLBACK, 
); 
    return $items; 
} 


function test_module_form() { 
return drupal_get_form('test_module_my_form'); 

} 
function test_module_my_form($form, &$form_state) { 

$form['house'] = array(
    '#type' => 'radios', 
    '#options' => drupal_map_assoc(array(t('None'), t('Choose a house'))), 
    '#title' => t('Choose a house'), 
    '#default_value' => variable_get('house', 'None'), 
    '#required' => 'TRUE', 
); 
} 
?> 

回答

1

...

$images = array(
1 => 'theme('image_style', array('style_name' => 'stylename', 'path' =>'/path/to/file.jpg', 'alt' => 'image alt', 'title' => 'image title',)), 
2 => 'theme('image_style', array('style_name' => 'stylename', 'path' => '/path/to/file2.jpg', 'alt' => 'image alt', 'title' => 'image title',)), 
); 

在可能情況下,我是用imagecache預設圖像。設置您的陣列與上述類似,或使用主題(「形象」,...)

然後像...

$form['house'] = array(
    '#type' => 'radios', 
    '#options' => $images, 
    '#title' => t('Choose a house'), 
    '#default_value' => variable_get('house', 'None'), 
    '#required' => 'TRUE', 
); 

在我來說,我創建了$圖像陣列動態和所使用的fid as key