You are here

function antispam_form_alter in AntiSpam 6

Same name and namespace in other branches
  1. 7 antispam.module \antispam_form_alter()

Implementation of hook_form_alter().

File

./antispam.module, line 856

Code

function antispam_form_alter(&$form, $form_state, $form_id) {

  // Hook into comment edit/reply form.
  if ($form_id == 'comment_form' && variable_get('antispam_check_comments', 1)) {

    // ...only if current user is not moderator.
    if (!antispam_is_spam_moderator('comments')) {

      // ...also check if AntiSpam connections are enabled.
      if (variable_get('antispam_connection_enabled', 1)) {
        $form['#submit'][] = '_antispam_comment_form_submit';
      }

      // Inject anti-spambot code, if requested to.
      if (antispam_is_anti_spambot_enabled()) {
        $form['#validate'][] = '_antispam_comment_form_validate';
      }
    }
  }
  else {
    if (isset($form['type']) && $form['type']['#value'] . '_node_form' == $form_id) {

      // ...only if current user is not moderator.
      if (!antispam_is_spam_moderator('comments')) {

        // ...also check if it's about a node type that we have been explicitly requested to check.
        $check_nodetypes = variable_get('antispam_check_nodetypes', array());
        $node_type = $form['type']['#value'];
        if (is_array($check_nodetypes) && isset($check_nodetypes[$node_type]) && $check_nodetypes[$node_type]) {

          // Inject anti-spambot code, if requested to.
          if (antispam_is_anti_spambot_enabled()) {
            $form['#validate'][] = '_antispam_node_form_validate';
          }
        }
      }
    }
  }
}