Drupal二次开发的时候,我们时常要使用到多选列表,但是官方默认的多选下拉列表,是在不敢恭维如下图所示:
不过难看不可怕,Drupal有两万第三方模块做支撑,只有你想不到,没有找不到的。
功夫不负有心人,终于找到一款相貌极佳的module。于是拿过来使用,切看我慢慢道来,该去如何使用它。
第一:去官网下载模块,安装。
第二:安装完毕,接下来就要使用到Form API开发中去
/** * hook_menu(). * @author masx */ function front_menu(){ $items['formexample'] = array( 'title' => 'View the sample form', 'page callback' => 'drupal_get_form', 'page arguments' => array('front_nameform'), 'access callback' => TRUE, 'type' => MENU_NORMAL_ITEM ); return $items; } /** * Define a form. 构造表单 */ function front_nameform() { $form['user_name'] = array( '#title' => t('Your Name'), '#type' => 'textfield', '#description' => t('Please enter your name.'), ); $form['selected'] = array( '#type' => 'select', '#title' => t('Selected'), '#multiple' => 3, '#options' => array( 0 => t('驴儿'), 1 => t('牛儿'), 2 => t('狗儿'), 3 => t('猫儿'), 4 => t('驴儿'), 5 => t('牛儿'), ), '#description' => t('Set this to <em>Yes</em> if you would like this category to be selected by default.'), ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); return $form; } /** * Handle post-validation form submission.处理表单 */ function front_nameform_submit($form, &$form_state) { $name = $form_state['values']['user_name']; drupal_set_message(t('Thanks for filling out the form, %name', array('%name' => $name)));} }第三:显示效果