2

I'm trying to make a radio box display an image next to it when selected with drupal 7 form api,and I've no idea where to start. I'd appreciate some help.Thank you

This is the code I'm using:

 <?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',
);
}
?>
Jonas
  • 121,568
  • 97
  • 310
  • 388
John
  • 21
  • 1
  • 3

1 Answers1

1

I just figured this out...

$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',)),
);

In may case I was using imagecache presets for the image. Set up your array similar to above, or using theme('image', ...)

then something like...

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

In my case I created the $images array dynamically and used the fid as key

Hunter
  • 11
  • 1