View source
<?php
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>';
}
}
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 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);
}
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;
}
}
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;
}