function text_captcha_captcha in CAPTCHA 6
Same name and namespace in other branches
- 5.3 text_captcha/text_captcha.module \text_captcha_captcha()
Implementation of hook_captcha
File
- text_captcha/
text_captcha.module, line 40
Code
function text_captcha_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
return array(
'Text',
);
case 'generate':
// Add in the necessary functions
require_once drupal_get_path('module', 'text_captcha') . '/text_captcha.user.inc';
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,
'#size' => 15,
'#required' => TRUE,
);
return $result;
}
}
}