You are here

function word_list_captcha_captcha in CAPTCHA Pack 5

Same name and namespace in other branches
  1. 8 text_captcha/modules/word_list_captcha/word_list_captcha.module \word_list_captcha_captcha()
  2. 6 text_captcha/word_list_captcha/word_list_captcha.module \word_list_captcha_captcha()
  3. 7 text_captcha/word_list_captcha/word_list_captcha.module \word_list_captcha_captcha()

Implementation of hook_captcha().

File

text_captcha/word_list_captcha/word_list_captcha.module, line 102

Code

function word_list_captcha_captcha($op, $captcha_type = '', $post_data = array()) {
  switch ($op) {
    case 'list':
      return array(
        'Pick the unrelated word',
      );
      break;
    case 'generate':
      if ($captcha_type == 'Pick the unrelated word') {
        $list_size = (int) variable_get('word_list_captcha_list_size', 5);
        list($word_list, $wrong_word) = _word_list_captcha_get_word_list_captcha($list_size);

        // build options list
        $options = array();
        foreach ($word_list as $word) {
          $options[$word] = $word;
        }
        $captcha = array();
        $captcha['solution'] = $wrong_word;
        $captcha['form']['captcha_response'] = array(
          '#type' => 'radios',
          '#title' => t('Which word does not belong to the list?'),
          '#options' => $options,
          // extra class needed for additional CSS'ing of the options
          '#attributes' => array(
            'class' => 'text-captcha-word-list-radios',
          ),
          // The following entry '#DANGEROUS_SKIP_CHECK' is needed to prevent
          // that Drupal checks during validation phase if a submitted option
          // is in the list of possible options. (see includes/form.inc)
          // The options are randomly generated on each call and consequently
          // almost never the same during the generate phase and the validation
          // phase.
          '#DANGEROUS_SKIP_CHECK' => TRUE,
          //
          '#required' => TRUE,
        );

        // additional text CAPTCHA CSS rules
        drupal_add_css(drupal_get_path('module', 'word_list_captcha') . '/../text_captcha.css');
        return $captcha;
      }
      break;
  }
}