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.    */
  7.  
  8. function my_module_form_alter($form_id, &$form) {
  9.  
  10.   switch ($form_id) {
  11.     case 'comment_form' :
  12.       if ($site == 'comments') {
  13.         $subject = 'Re: ' . decode_entites(drupal_get_title());
  14.         $form['#submit']['my_module_comment_form_submit'] = array($subject);
  15.  
  16. /**This next line was the solution to my problem from the FAPI handbook page:
  17.   *  http://drupal.org/node/58689
  18.   *  By reversing the order of the submits, my submit gets done and the default
  19.   *  comment form submit doesn't overwrite my desired subject line.
  20.   */
  21.         $form['#submit'] = array_reverse($form['#submit']);
  22.         return $form;  
  23.       }
  24.     break;    
  25.   }
  26. }
  27.  
  28. function my_module_comment_form_submit($form, $form_values, $subject) {
  29.  
  30. /**
  31.   * Note: this code almost works, for some reason only the first part of the string
  32.   * gets passed with the $subject parameter, i.e. subject line is always 'Re: ' - node
  33.   * title doesn't get passed. I'll figure this out next.
  34.  */
  35.        
  36.  if ($form_values['subject'] == '') {
  37.     $form_values['subject'] = $subject;
  38.   }
  39. }