跳转到主要内容
learningxm 提交于 13 October 2014
<?php
//--hook_node_view($node, $view_mode, $langcode)
function addtabexample_node_view($node, $view_mode, $langcode)
{
    $my_form = drupal_get_form('addtabexample_form', $node);
    $node->content['my_form_attached'] = array(
        '#markup' => drupal_render($my_form),
        '#weight' => 10,
    );
}

//--预定义的表单
function addtabexample_form($node, &$form_state) {

  $form['title'] = array(
    '#type' => 'textfield', 
    '#title' => 'Title' , 
    '#default_value' => !empty($node->title) ? $node->title : '', 
    '#required' => TRUE, 
    '#weight' => -5,
  );

  $form['field1'] = array(
    '#type' => 'textfield', 
    '#title' => t('Custom field'), 
    '#default_value' => '', 
    '#maxlength' => 127,
 );
  return $form;
}
?>

 

http://stackoverflow.com/questions/11494439/how-to-programmatically-add-a-form-to-a-node-in-drupal-7?rq=1

Drupal 版本