You are here

function captcha_captcha in CAPTCHA 5.3

Same name and namespace in other branches
  1. 8 captcha.module \captcha_captcha()
  2. 6.2 captcha.module \captcha_captcha()
  3. 6 captcha.module \captcha_captcha()
  4. 7 captcha.module \captcha_captcha()

Default implementation of hook_captcha

1 call to captcha_captcha()
image_captcha_captcha in image_captcha/image_captcha.module
Implementation of hook_captcha().

File

./captcha.module, line 794
This module enables basic CAPTCHA functionality: administrators can add a CAPTCHA to desired forms that users without the 'skip CAPTCHA' permission (typically anonymous visitors) have to solve.

Code

function captcha_captcha($op, $captcha_type = '') {
  switch ($op) {
    case 'list':
      return array(
        'Math',
      );
    case 'generate':
      if ($captcha_type == 'Math') {
        $result = array();
        $answer = mt_rand(1, 20);
        $x = mt_rand(1, $answer);
        $y = $answer - $x;
        $result['solution'] = "{$answer}";
        $result['form']['captcha_response'] = array(
          '#type' => 'textfield',
          '#title' => t('Math Question'),
          '#description' => t('Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.'),
          '#field_prefix' => t('@x + @y = ', array(
            '@x' => $x,
            '@y' => $y,
          )),
          '#size' => 4,
          '#maxlength' => 2,
          '#required' => TRUE,
        );
        return $result;
      }
  }
}