Fix for Trying to insert text into "subject" field of the comments form.

  1. /**
  2.    * Implements hook_form_alter.
  3.    * Client wants the subject field to initially be blank.
  4.    * If the user doesn't type in a subject line, then the
  5.    * node title should be inserted in the subject field.
  6.   * Currently in the code below, the form_alter puts the node title as the
  7.   * #default_value in the subject field.
  8.    */
  9. function external_page_form_alter($form_id, &$form) {
  10.   $site = strtok($_SERVER['SERVER_NAME'], '.');
  11.   switch ($form_id) {
  12.     case 'comment_form' :
  13.       if ($site == 'comments') {
  14.         $subject = 'Re: ' . drupal_get_title();
  15.        $form['subject'] = array (
  16.        '#type' => textfield,
  17.        '#title' => 'Subject',
  18.        '#default_value' => decode_entities($subject),
  19.        );
  20.       }
  21.     break;    
  22.   }
  23. }
  24. function external_page_comment_form_validate($form_id, $form_values) {
  25.         //Not validating anything just now.
  26. }
  27. function external_page_comment_form_submit($form, $form_values) {
  28.  
  29. /**
  30.   * Note: this code doesn't work, what happens is that if the subject field is blank
  31.   * then it somehow gets populated with the first part of the first sentence i of the
  32.   * text in the the comment field.
  33.  */
  34.        
  35.  if ($form_values['subject'] == '') {
  36.     $subject = 'Re: ' . drupal_get_title();
  37.     $form_values['subject'] = $subject;
  38.     //form_set_value($form_values['subject'], $subject);
  39.   }
  40. }