6

如何在“创作信息发布选项”部分下方的节点编辑表单中添加自定义配置区域?

4

2 回答 2

14

您可以使用 hook_form_FORM_ID_alter()。下面的例子:

function my_module_form_node_form_alter(&$form, $form_state) {
  // if you are targeting a specific content type then 
  // you can access the type:
  $type = $form['#node']->type;
  // Then
  if ($type == 'my_content_type') {
  //  use a contact settings for the sake of this example
   $form['contact'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Contact settings'), 
    '#weight' => 100, 
    '#collapsible' => TRUE, 
    '#collapsed' => FALSE,
   );
   // add simple checkbox to the field set
   $form['contact']['approve'] = array(
     '#type' =>'checkbox', 
     '#title' => t('Contact me'),
   );
  } 
}

现在为了存储数据,我鼓励您查看示例项目;它有许多代码示例和大量文档。此外,请查看Form API以获取有关不同类型表单元素的更多信息。希望这可以帮助。

于 2012-11-25T02:41:31.807 回答
4

以下代码生成附加图像中的最后一个菜单:

    $form['barclays_epdq'] = array(
        '#type' => 'fieldset',
        '#access' => TRUE,
        '#title' => 'Barclays ePDQ',
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
        '#group' => 'additional_settings',
        '#weight' => 100,
        'barclays_epdq_active' => array(
            '#type' => 'checkbox',
            '#title' => 'Enable this webform to send users to your Barclays ePDQ store to make a payment',
            '#default_value' => $active_state,
        ),
    );

在此处输入图像描述

ps:表格在hook_form_alter

于 2012-11-27T14:26:40.180 回答