You are here

foo_captcha.module in CAPTCHA Pack 6

File

foo_captcha/foo_captcha.module
View source
<?php

/**
 * Implementation of hook_help().
 */
function foo_captcha_help($path, $arg) {
  switch ($path) {
    case 'admin/user/captcha/foo_captcha':
      return '<p>' . t('This is a very simple CAPTCHA, which requires users to enter "foo" in a textfield.') . '</p>';
  }
}

/**
 * Implementation of hook_menu().
 */
function foo_captcha_menu() {
  $items = array();
  $items['admin/user/captcha/foo_captcha'] = array(
    'title' => 'Foo CAPTCHA',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'foo_captcha_settings_form',
    ),
    'access arguments' => array(
      'administer CAPTCHA settings',
    ),
    'type' => MENU_LOCAL_TASK,
  );
  return $items;
}

/**
 * Function for the settings form
 */
function foo_captcha_settings_form() {
  $form = array();
  $form['foo_captcha_ignore_spaces'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore spaces in the response'),
    '#default_value' => variable_get('foo_captcha_ignore_spaces', FALSE),
  );
  return system_settings_form($form);
}

/**
 * Implementation of hook_captcha().
 */
function foo_captcha_captcha($op, $captcha_type = '') {
  switch ($op) {
    case 'list':
      return array(
        'Foo CAPTCHA',
      );
      break;
    case 'generate':
      if ($captcha_type == 'Foo CAPTCHA') {
        $captcha = array();
        $captcha['solution'] = 'foo';
        $captcha['form']['captcha_response'] = array(
          '#type' => 'textfield',
          '#title' => t('Enter "foo"'),
          '#required' => TRUE,
          '#process' => array(
            'foo_captcha_process',
          ),
        );
        return $captcha;
      }
      break;
  }
}

/**
 * Process the response to the foo CAPTCHA before validation.
 */
function foo_captcha_process($element, $edit, &$form_state, $complete_form) {
  if (variable_get('foo_captcha_ignore_spaces', FALSE)) {
    $element['#value'] = preg_replace('/\\s*/', '', $element['#value']);
  }
  return $element;
}

Functions

Namesort descending Description
foo_captcha_captcha Implementation of hook_captcha().
foo_captcha_help Implementation of hook_help().
foo_captcha_menu Implementation of hook_menu().
foo_captcha_process Process the response to the foo CAPTCHA before validation.
foo_captcha_settings_form Function for the settings form