You are here

function comment_notify_form_alter in Comment Notify 5

Same name and namespace in other branches
  1. 5.2 comment_notify.module \comment_notify_form_alter()
  2. 6 comment_notify.module \comment_notify_form_alter()
  3. 7 comment_notify.module \comment_notify_form_alter()

Insert our checkbox, and populate fields. set validation hook.

File

./comment_notify.module, line 51
This module provides comment follow-up e-mail notification for anonymous and registered users.

Code

function comment_notify_form_alter($form_id, &$form) {
  global $user;
  if ($form_id != 'comment_form') {
    return;
  }
  $op = isset($_POST['op']) ? $_POST['op'] : '';
  if ($op == t('Preview comment')) {
    drupal_set_message(t('ATTENTION: Your comment is NOT YET posted - please click the post button to confirm your post'));

    //extra submit button on top
    if (!form_get_errors() && (variable_get('comment_preview', COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL || $op == t('Preview comment') || $op == t('Post comment'))) {
      $form['submitextra'] = array(
        '#type' => 'fieldset',
        '#title' => t('Comment is not posted yet - please click post button to confirm your post'),
        '#weight' => -99,
        '#collapsible' => FALSE,
      );
      $form['submitextra']['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Post comment'),
        '#weight' => -20,
      );
    }
  }
  if ($user->uid == 0 || variable_get('comment_notify_regged_checkbox', TRUE)) {
    $form['notify'] = array(
      '#type' => 'checkbox',
      '#title' => t('Notify me of follow-up comments posted here.'),
      '#default_value' => $user->uid != 0 ? $user->comment_notify_mailalert : variable_get('comment_notify_default_anon_mailalert', TRUE),
    );
  }
  else {
    $form['notify'] = array(
      '#type' => 'hidden',
      '#title' => t('Mail me updates to this comment.'),
      '#default_value' => $user->comment_notify_mailalert,
    );
  }
  if ($form['cid']['#value'] != '') {
    $form['notify']['#default_value'] = $form['#parameters'][1]['notify'];
  }
}