You are here

function text_captcha_captcha in CAPTCHA 5.3

Same name and namespace in other branches
  1. 6 text_captcha/text_captcha.module \text_captcha_captcha()

Implementation of hook_captcha

File

text_captcha/text_captcha.module, line 162
Implementation of a text based CAPTCHA.

Code

function text_captcha_captcha($op, $captcha_type = '') {
  switch ($op) {
    case 'list':
      return array(
        'Text',
      );
    case 'generate':
      if ($captcha_type == 'Text') {

        // generate words
        $words = _text_captcha_generate_words((int) variable_get('text_captcha_word_quantity', 5));

        // pick a random word
        $key = array_rand($words, 1);
        $answer = $words[$key];

        // store the answer and build the form elements
        $result = array();
        $result['solution'] = $answer;
        $result['form']['captcha_response'] = array(
          '#type' => 'textfield',
          '#title' => t('What is the @nth word in the phrase "@words"?', array(
            '@nth' => _text_captcha_ordinal($key + 1),
            '@words' => implode(' ', $words),
          )),
          '#weight' => 0,
          '#required' => TRUE,
          '#size' => 15,
        );
        return $result;
      }
  }
}