【问题标题】:Create Drupal Form in Table在表中创建 Drupal 表单
【发布时间】:2011-11-16 21:52:41
【问题描述】:

我尝试创建一个表格,其中一行如下所示:

|Text1|Text2|Button1|

只要用户单击按钮,我就想将 Button1 与两个 textFields 和另一个按钮进行交换……所以这是一个正常的 AJAX 请求。 我试图实现这一点,不确定这是否是正确的方法,让我知道我是否可以用完全其他的方式来实现它:S

所以我已经做了: 在我的 hook_menu 中,我链接到一个返回数据的函数:

return theme ( 'my_theme_function', array (
                    'running' => true, 
                    'form' => $database->getData ()
            ) );

getData()-Function 中发生了什么: 我使用 drupal_get_form(..).. 从给定的表单返回的表单是这样的:

$data = array (
                    'items' => $finder->getGamesToPlayForm ( $form_state ), 
                    '#title' => 'Title'
            );

$finder 返回我想在表格中显示的项目列表。所以没什么特别的。

my_theme_function 设置为使用模板文件,我想在其中显示全部内容。 这看起来像这样:

$header = array (
        'Col1', 
        'Col2', 
        '' 
);

$rows = array ();

foreach ( element_children ( $formData ['items'] ) as $gameId ) {
    $row = array ();
    $row [] = drupal_render ( $formData ['items'] [$gameId] ['#col1'] );
    $row [] = drupal_render ( $formData ['items'] [$gameId] ['#col2'] );
    $row [] = drupal_render ( $formData ['items'] [$gameId] ['#form'] );
    $rows [] = $row;
}
$output = theme ( 'table', array (
        'header' => $header, 
        'rows' => $rows 
) );

unset($formData['items']);


$output .= drupal_render_children ( $formData );

print $output

这样,一切都打印正确。但是没有“表单”标签,这会阻止我的表单工作..

那么,任何想法/提示如何解决此类问题?可能我走错路了..

【问题讨论】:

  • 一切似乎都还好,但我不明白But there are no ""-tags的意思
  • 这应该是 "form"-tags :P 现在,我删除了所有这些东西,并在前缀和后缀中添加了表格内容.. 这很好用......

标签: drupal drupal-7 drupal-fapi


【解决方案1】:

试试

'render element' => 'form'

在您的主题中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多