【问题标题】:Why this drupal form not working?为什么这种 Drupal 表单不起作用?
【发布时间】:2011-10-03 17:09:03
【问题描述】:

Drupal 7,$output 在我的页面上显示字符串“Array”,我不知道为什么,这是代码:

它只能这样工作:return drupal_get_form('test_exp_form')

但我需要将 html 和文本添加到我的 $output 变量中,我不能只返回表单。

function test_page() {
     $output = '<div>Hello</div>';
     $output = drupal_get_form('test_exp_form');
     return $output;
}

function test_exp_form($form, &$form_stat) {
  $form = array();

    $form['example_textfield'] = array(
      '#type' => 'textfield',
      '#title' => t('Example Textfield'),
      '#default_value' => 'some text',
    );

  return $form;
}

【问题讨论】:

    标签: php forms drupal drupal-7


    【解决方案1】:

    您需要在 Drupal 7 中使用 render() 函数,因为 drupal_get_form 返回一个“渲染数组”:

    function test_page() {
      $output = '<div>Hello</div>';
      $output .= render(drupal_get_form('test_exp_form'));
      return $output;
    }
    

    以下是有关 Drupal 7 中渲染数组的更多信息:

    Render arrays in Drupal 7

    【讨论】:

    • 我已经更新了答案中的代码,我刚刚测试过了,它可以工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多