'. t('This is a very simple CAPTCHA, which requires users to enter "foo" in a textfield.') .'

'; } } /** * 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; }