我正在将一组表单发送到模板,但如果我想呈现单个表单元素,我很难弄清楚如何打印开始和结束表单标签。
这是一个示例,可让您了解发送到主题功能的结构:
function mymodule_page_callback() {
...
$i = 0;
foreach ($widgets as $widget) {
$forms[] = drupal_get_form('my_renderable_form_' . $i, $widget);
$i++;
}
return theme('my_theme_function', array('forms' => $forms));
}
在我的模板中,我正在构建一个每行包含 1 个表单的表格。这是我可以使它工作的唯一方法:
$header = array('field 1', 'field 2', '');
foreach ($variables['forms'] as $form) {
$row = array(
drupal_render($form['field1']),
drupal_render($form['field2']),
// Manually set the closing form tag
drupal_render($form['submit']) . drupal_render_children($form) . '</form>'
);
// Now drupal_render($form) to get the opening/closing form tags
// and stuff it at the beginning of the 1st column.
// This has to be done last so the rest of the form doesn't render with it.
$row[0] = str_replace('</form>', '', drupal_render($form)) . $row[0];
$rows[] = $row;
}
print theme('table', array('header' => $header, 'rows' => $rows);
是否有适当的方法来呈现每个表单的打开和关闭?