You are here

function captcha_elements in CAPTCHA 6.2

Implementation of hook_elements().

File

./captcha.module, line 148
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_elements() {

  // Define the CAPTCHA form element with default properties.
  $captcha_element = array(
    '#input' => TRUE,
    '#process' => array(
      'captcha_process',
    ),
    // The type of challenge: e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image', ...
    '#captcha_type' => 'default',
    '#default_value' => '',
    // CAPTCHA in admin mode: presolve the CAPTCHA and always show it (despite previous successful responses).
    '#captcha_admin_mode' => FALSE,
    // The default CAPTCHA validation function.
    // TODO: should this be a single string or an array of strings (combined in OR fashion)?
    '#captcha_validate' => 'captcha_validate_strict_equality',
  );

  // Override the default CAPTCHA validation function for case insensitive validation.
  // TODO: shouldn't this be done somewhere else, e.g. in form_alter?
  if (CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE == variable_get('captcha_default_validation', CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE)) {
    $captcha_element['#captcha_validate'] = 'captcha_validate_case_insensitive_equality';
  }
  return array(
    'captcha' => $captcha_element,
  );
}