1

I have added a new field to my comment form and this is how my comment form look liks:

enter image description here

So you can see it does not look nice, I want to have the description on top of the input box, where I say: Which paragraph do you want to put comment on?(Enter 0 if you ant to put comment on the whole article). So How can I do it?

This is the function that I have used to add the new field to comment form:

  function Annotations_form_comment_form_alter(&$form, &$form_state, $form_id) {
$form['paragraph_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Which paragraph you want to put comment on?(Enter 0 if you want to put comment on the whole article.)') . "<br>",
    '#required' => TRUE,
    '#size' => 10,
    '#maxlength' => 2,
    '#default_value' => !empty($form['#entity']->paragraph_id) ? $form['#entity']->paragraph_id : NULL, // set the default value to the current paragraph value
    '#weight' => $form['subject']['#weight'] + 1, // place after the subject field by setting the weight to +1 of subject weight
);

$form['#validate'][] = 'annotations_form_comment_form_validate';
$form['#submit'][] = 'annotations_form_comment_form_submit';

}

1 Answer 1

1

You need to add a description field to your array:

$form['paragraph_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Your Title'),
    '#description' => t('The paragraph you would like to put a comment on (enter 0 if you want to put the comment on the entire article'),
    ...
);

This way the explanation will show up under the field.

4
  • Thank you, it worked, So what if I want to have the field under the description?@Klaus Sonnenleiter Oct 22, 2014 at 3:48
  • I think that's a matter of how your theme will arrange things on the page. Without getting too deep into it, and since theming is quite a large field to get familiar with, it's probably easiest, if you simply download a couple of themes and see how they change your look and feel. Once you're comfortable with changing templates, look for "*.tpl.php" files in your theme's folder. Oct 22, 2014 at 14:49
  • thanks, so what about comment part? You can see that the "Comment" is on one line, and under it is the comment input box. How can I have something like that? Oct 22, 2014 at 15:47
  • This is done in the "Manage Display" section of your content type. I think what you want is to set the label to "inline" instead of "above". Oct 23, 2014 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.