Drupal7.x 在theme table 里嵌入form元素

有时候需要在drupal theme 渲染的表格里插入一些表单元素,比如表格里加入上传文件功能。那么如何操作呢?

1.在模块下的yourModule.module 文件下些一个hook

function yourModuleName_theme() {
  return array(
      'customize_table'  => array(
          'render element' => 'form',
      ),
  );
}

2.我新建了一个customize_table.inc,构造需要在主题中渲染的表单元素
function customize_table($form, &$form_state) {
    $form['table_column1'] = array(
      '#type' => 'value',
      '#value'=> '表格值'
    );
    $form['table_column2'] = array(
      '#type' => 'value',
      '#value'=> '表格值'
    );

    $form['table_file'] = array(
      '#type' => 'managed_file',
      '#upload_locaiton'=> 'public://yourModulePath/table'
    );

}



3.在customize_table.inc文件中注册一个主题渲染table

function theme_customize_table($variables) {

    $form = $variables['form'];

   $header = array('列1', '列2', '列3');

   $rows[] = array(

       $form['table_column1'],

       $form['table_column2'],

      render($form['table_file']),

   );

  $output = theme('table', array('header' => $header, 'rows' => $rows));

  $output .= drupal_render_children($form);

  return $output;

}

4.打开方法customize_table对应的链接就能看到渲染的表格中第三列里有一个上传文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值