You are here

function _cleantalk_form_alter in Anti Spam by CleanTalk 8

Same name and namespace in other branches
  1. 8.4 cleantalk.module \_cleantalk_form_alter()
  2. 8.3 cleantalk.module \_cleantalk_form_alter()
  3. 7.5 cleantalk.module \_cleantalk_form_alter()
  4. 7 cleantalk.module \_cleantalk_form_alter()
  5. 7.2 cleantalk.module \_cleantalk_form_alter()
  6. 7.4 cleantalk.module \_cleantalk_form_alter()
  7. 9.1.x cleantalk.module \_cleantalk_form_alter()

Cleantalk inner function - alters needed form.

6 calls to _cleantalk_form_alter()
cleantalk_form_comment_form_alter in ./cleantalk.module
Implements hook_form_BASE_FORM_ID_alter().
cleantalk_form_comment_node_webform_form_alter in ./cleantalk.module
Implements hook_form_BASE_FORM_ID_alter()
cleantalk_form_contact_message_feedback_form_alter in ./cleantalk.module
cleantalk_form_contact_personal_form_alter in ./cleantalk.module
Implements hook_form_FORM_ID_alter().
cleantalk_form_contact_site_form_alter in ./cleantalk.module
Implements hook_form_FORM_ID_alter().

... See full list

File

./cleantalk.module, line 703
Main CleanTalk integration module functions.

Code

function _cleantalk_form_alter(&$form, &$form_state, $form_id) {
  static $js_cookie_added = FALSE;
  $ct_link = \Drupal::config('cleantalk.settings')
    ->get('cleantalk_link');
  if ($ct_link != 0) {
    $form['cleantalk_link'] = array(
      '#type' => 'item',
      '#markup' => t("<a href='https://cleantalk.org/drupal-anti-spam-module-wo-captcha'>Drupal spam</a> blocked by CleanTalk."),
      '#required' => FALSE,
      '#weight' => 999,
    );
  }
  $js_cookie_added = TRUE;
  if ($form_id == 'user_register_form') {
    $session_time_key = 'ct_submit_register_time';
    $form['#validate'][] = 'cleantalk_validate_register';
  }
  else {
    $session_time_key = 'ct_submit_comment_time';
    if ($form_id == 'comment_comment_form' || $form_id == 'comment_form') {
      $form['#validate'][] = 'cleantalk_validate_comment';
    }
    if ($form_id == 'contact_site_form' || $form_id == 'contact_personal_form' || $form_id == 'contact_message_feedback_form') {
      $form['#validate'][] = 'cleantalk_validate_contact_message';
    }
    else {
      if (\Drupal::config('cleantalk.settings')
        ->get('cleantalk_ccf') == 1) {
        $form['#validate'][] = 'cleantalk_validate_contact_message';
      }
    }
  }

  //drupal_session_start();

  //$_SESSION[$session_time_key] = REQUEST_TIME;
  $field_name = 'ct_checkjs';
  $ct_check_def = '0';
  if (!isset($_COOKIE[$field_name])) {
    setcookie($field_name, $ct_check_def, 0, '/');
  }
}