0

drupal コメント フォームに「名前」フィールドを 1 つ追加する必要があります。これを 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;
}
}

私を助けてください

4

1 に答える 1

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

その理由は、他のフィールドにも重みを設定する必要があるためです。これは、カスタム フィールドの重みを設定するのに役立ちます。

上記のスニペットが役立つと思います。さらに必要な場合はお知らせください。間違いなく役立ちます。

于 2012-05-25T13:55:22.467 に答える