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) {
  $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';

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

 $form['comment_body'][LANGUAGE_NONE][0]['#default_value'] = "Your default value";
  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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