2012-05-25 102 views
0

我需要在drupal評論表單中添加一個額外的「名稱」字段。我使用hook_form_alter實現了這個。現在該領域即將到來。我無法控制它的位置。現在它是最後一次。我改變了重量,然後也沒有影響。向drupal添加額外的字段6評論表格

function comment_extra_form_alter(&$form, &$form_state, $form_id) { 
global $user; 
$output = ''; 
    if (!$user->uid) { 
    switch ($form_id) {   
      case 'comment_form': 
      $form['admin']['name'] = array(
       '#type' => 'textfield', 
       '#title' => t('Name'), 
       '#weight' => -1, 
       '#size' => 60, 
       '#maxlength' => 60, 
       '#default_value' => $author, 

      ); 

      $output .= comment_render($form); 

      break; 
    } 
    return $output; 
} 
} 

請幫我

回答

0

請試試這個片斷,讀理由。

function hook_form_alter(&$form, &$form_state, $form_id) { 
    global $user; 
    $output = ''; 
    switch ($form_id) { 
    case 'comment_form': 
    $form['_author']['#weight'] = -50; 
    $form['subject']['#weight'] = -49; 
    $form['name'] = array(
    '#type' => 'textfield', 
    '#title' => t('Name'), 
    '#weight' => -48, 
    '#size' => 60, 
    '#maxlength' => 60, 
    '#default_value' => $user, 
    ); 
    $form['comment_filter']['#weight'] = -47; 
    $output .= comment_render($form); 
    break; 
} 
return $output; 
} 

的原因是:你還需要設置權重等領域以及,它可以幫助您設置體重您自定義字段。

我覺得上面的代碼會幫助你。如果需要進一步的需要請讓我知道,一定會有所幫助。