Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am using hook_form_comment_form_alter to add values to the textboxes in the commenting form. But in the comment body I can seem to add a default value and can't seem to find a value that I can change. Does anyone have any ideas?

function mytheme_form_comment_form_alter(&$form, &$form_state, $form_id) {
  dpm(get_defined_vars());
  $form['author']['name']['#title'] = "";
  $form['author']['name']['#default_value'] = "Name";
  $form['author']['name']['#title'] = "";
  $form['author']['mail']['#default_value'] = "Email";
  $form['author']['mail']['#title'] = "";
  $form['author']['homepage']['#default_value'] = "Website";
  $form['author']['homepage']['#title'] = "";
  $form['author']['subject']['#default_value'] = "Subject";
  //$form['comment_body']['need default value']= 'I need to add a value';
}
share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

To add default value to your comment form body use the following snippet,

 $form['comment_body'][LANGUAGE_NONE][0]['#default_value'] = "Your default value";
share|improve this answer
1  
I think you should use LANGUAGE_NONE constant instead of directly using 'und' –  Mathankumar Nov 22 '12 at 9:51
    
@mathan you re right, i edited my answer –  Anoop Joseph Nov 22 '12 at 10:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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