You are here

function _cleantalk_form_alter in Anti Spam by CleanTalk 7

Same name and namespace in other branches
  1. 8.4 cleantalk.module \_cleantalk_form_alter()
  2. 8 cleantalk.module \_cleantalk_form_alter()
  3. 8.3 cleantalk.module \_cleantalk_form_alter()
  4. 7.5 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.

5 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_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().
cleantalk_form_user_register_form_alter in ./cleantalk.module
Implements hook_form_FORM_ID_alter().

File

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

Code

function _cleantalk_form_alter(&$form, &$form_state, $form_id) {
  static $js_cookie_added = FALSE;

  /*if ($js_cookie_added) {
      return;
    }*/
  $ct_link = variable_get('cleantalk_link', 0);
  if ($ct_link != 0) {
    $form['terms_of_use'] = array(
      '#type' => 'item',
      '#markup' => t("<a href='https://cleantalk.org/drupal-anti-spam-module-wo-captcha'>Drupal spam</a> blocked by CleanTalk."),
      '#required' => FALSE,
    );
  }
  $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 == 'contact_site_form' || $form_id == 'contact_personal_form') {
      $form['#validate'][] = 'cleantalk_validate_contact_message';
    }
    else {
      $form['#validate'][] = 'cleantalk_validate_comment';
    }
  }
  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, '/');
  }

  // We cannot place JS in separate file.
  // Because it is not static - we have to use generated values.

  /*  $ct_check_value = _cleantalk_get_checkjs_value();
    $js_template = 'function ctSetCookie(c_name, value, def_value) {
    document.cookie = c_name + "=" + escape(value.replace(/^def_value$/, value)) + "; path=/";
  }
  setTimeout("ctSetCookie(\"%s\", \"%s\", \"%s\");",1000);';
    $js_addon_body = sprintf($js_template, $field_name, $ct_check_value, $ct_check_def);

    drupal_add_js($js_addon_body,
      array(
        'type' => 'inline',
        'scope' => 'footer',
        'weight' => 5,
        'cache' => FALSE,
        'every_page' => FALSE,
      )
    );*/
}