【问题标题】:How to add input field to an element in Drupal hook_elements如何将输入字段添加到 Drupal hook_elements 中的元素
【发布时间】:2010-10-15 18:56:27
【问题描述】:

我已经用 hook_elements 创建了一个新元素。但是如何向它添加一个像 textfield 这样的输入元素呢?
我写了以下代码,文本框显示在表单上,​​但是当我在表单的提交函数中打印 form_state 值时,没有任何值。处理函数是添加输入字段的正确位置吗?


function test_elements() {
  return array(
    'test_field' => array(
      '#input' => TRUE,
      '#process' => array('test_field_process'),
    )
  );
}

function theme_test_field($element) {
  $output =  $element['#title'];
  $output .= drupal_render($element['#txtbox']);
  return $output;
}

function test_field_process($element, $edit, &$form_state, $complete_form) {
  $element['#txtbox'] = array(
      '#type' => 'textfield',
      '#title' => 'Enter value'
  );
  return $element;
}

【问题讨论】:

    标签: drupal


    【解决方案1】:

    你是否实现了 hook_theme 来描述 test_field?

    喜欢

    function test_theme() {
          return array(
             'test_field' => array(
                'arguments'  => array('element' => NULL),
             ),
          );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 2014-05-07
      • 2016-03-14
      相关资源
      最近更新 更多