跳转到主要内容
由 coco11 提交于 14 January 2015

  Drupal二次开发的时候,我们经常要使用到多选列表,但是官方默认的多选下拉列表,如下图:

 

    视觉效果不堪入目,经过努力,找到了一款相貌不错的module。下面请看使用方法:

    第一:去官网下载(https://www.drupal.org/project/multiselect)模块,安装。

 

  第二:安装完毕,接下来就要使用到Form API开发中去

  1. <font face="微软雅黑">/**
  2. * hook_menu().
  3. * @author masx
  4. */
  5. function front_menu(){ $items['formexample'] = array(
  6. 'title' => 'View the sample form',
  7. 'page callback' => 'drupal_get_form',
  8. 'page arguments' => array('front_nameform'),
  9. 'access callback' => TRUE,
  10. 'type' => MENU_NORMAL_ITEM
  11.   );
  12.   return $items;
  13. } 
  14. /**
  15. * Define a form. 构造表单
  16. */
  17. function front_nameform() {
  18. $form['user_name'] = array(
  19.   '#title' => t('Your Name'),
  20.   '#type' => 'textfield',
  21.   '#description' => t('Please enter your name.'),
  22. );
  23.   $form['selected'] = array(
  24.        '#type' => 'select',
  25.        '#title' => t('Selected'),
  26.        '#multiple' => 3,
  27.        '#options' => array(
  28.           0 => t('驴儿'),
  29.           1 => t('牛儿'),
  30.           2 => t('狗儿'),
  31.           3 => t('猫儿'),
  32.           4 => t('驴儿'),
  33.           5 => t('牛儿'),
  34.        ),
  35.        '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'),
  36.    );
  37. $form['submit'] = array(
  38.   '#type' => 'submit',
  39.   '#value' => t('Submit')
  40. );
  41. return $form;
  42. }
  43. /**
  44. * Handle post-validation form submission.处理表单
  45. */
  46. function front_nameform_submit($form, &$form_state) {
  47.    $name = $form_state['values']['user_name'];
  48.    drupal_set_message(t('Thanks for filling out the form, %name',
  49.    array('%name' => $name)));}
  50. }</font>

  第三:显示效果如下:

 

 

Drupal 版本