在drupal 6注释表单中添加一个额外的字段

时间:2012-05-25 06:30:00

标签: drupal drupal-6 drupal-modules

我需要在drupal评论表单中添加一个额外的“名称”字段。我使用hook_form_alter实现了这个。现在这个领域即将到来。我无法控制它的位置。现在它即将到来。我改变了重量,然后也没有影响。

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;
}
}

请帮帮我

1 个答案:

答案 0 :(得分: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;
}

原因是:您还需要为其他字段设置权重,这有助于您设置自定义字段的权重。

我认为上面的代码片段可以帮到你。如果需要进一步需要请告诉我,肯定会有所帮助。

相关问题