You are here

function cleantalk_validate_contact_message in Anti Spam by CleanTalk 9.1.x

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

Cleantalk inner function - contact message validation function.

1 string reference to 'cleantalk_validate_contact_message'
_cleantalk_form_alter in ./cleantalk.module
Cleantalk inner function - alters needed form.

File

./cleantalk.module, line 192

Code

function cleantalk_validate_contact_message(&$form, &$form_state) {
  if (\Drupal::config('cleantalk.settings')
    ->get('cleantalk_check_contact_forms') && CleantalkFuncs::_cleantalk_check_form_submit_handlers($form_state
    ->getSubmitHandlers())) {
    $current_user = \Drupal::currentUser();
    $ct_temp_msg_data = CleantalkHelper::get_fields_any(\Drupal::request()->request
      ->all(), \Drupal::config('cleantalk.settings')
      ->get('cleantalk_fields_exclusions'));
    $spam_check = array();
    $spam_check['type'] = 'contact';
    if ($current_user
      ->id()) {
      $user = \Drupal\user\Entity\User::load($current_user
        ->id());
      $spam_check['sender_nickname'] = !empty($user
        ->get('name')) ? $user
        ->get('name')->value : '';
    }
    else {
      $spam_check['sender_nickname'] = $ct_temp_msg_data['nickname'] ? $ct_temp_msg_data['nickname'] : '';
    }
    $spam_check['sender_email'] = $ct_temp_msg_data['email'] ? $ct_temp_msg_data['email'] : '';
    $spam_check['message_title'] = $ct_temp_msg_data['subject'] ? $ct_temp_msg_data['subject'] : '';
    $spam_check['message_body'] = $ct_temp_msg_data['message'] ? $ct_temp_msg_data['message'] : '';
    $spam_result = CleantalkFuncs::_cleantalk_check_spam($spam_check, $form_state
      ->getErrors());
    if (isset($spam_result) && is_array($spam_result) && $spam_result['errno'] == 0 && $spam_result['allow'] != 1) {

      // Value of ct_result_comment is sanitized already (before storing).
      $form_state
        ->setErrorByName('message', strip_tags($spam_result['ct_result_comment'], '<p><a>'));
    }
  }
}