/[drupal]/contributions/modules/captcha/captcha.module
ViewVC logotype

Contents of /contributions/modules/captcha/captcha.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.100 - (show annotations) (download) (as text)
Sun Sep 20 10:57:07 2009 UTC (2 months ago) by soxofaan
Branch: MAIN
CVS Tags: DRUPAL-6--2-0, HEAD
Changes since 1.99: +21 -12 lines
File MIME type: text/x-php
added temporary workaround for the problem of admin CAPTCHA preview of the reCAPTCHA and Egglue CAPTCHA (discussed in http://drupal.org/node/487032 and http://drupal.org/node/525586) by disabling admin CAPTCHA preview for those challenges
1 <?php
2 // $Id: captcha.module,v 1.99 2009/09/10 22:31:50 soxofaan Exp $
3
4 /**
5 * @file
6 * This module enables basic CAPTCHA functionality:
7 * administrators can add a CAPTCHA to desired forms that users without
8 * the 'skip CAPTCHA' permission (typically anonymous visitors) have
9 * to solve.
10 *
11 */
12
13
14 define('CAPTCHA_PERSISTENCE_SHOW_ALWAYS', 1);
15 define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM', 2);
16 define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL', 3);
17
18 define('CAPTCHA_STATUS_UNSOLVED', 0);
19 define('CAPTCHA_STATUS_SOLVED', 1);
20 define('CAPTCHA_STATUS_EXAMPLE', 2);
21
22 define('CAPTCHA_DEFAULT_VALIDATION_CASE_SENSITIVE', 0);
23 define('CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE', 1);
24
25 /**
26 * Implementation of hook_help().
27 */
28 function captcha_help($path, $arg) {
29 switch ($path) {
30 case 'admin/help#captcha':
31 $output = '<p>'. t('"CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is typically a challenge-response test to determine whether the user is human. The CAPTCHA module is a tool to fight automated submission by malicious users (spamming) of for example comments forms, user registration forms, guestbook forms, etc. You can extend the desired forms with an additional challenge, which should be easy for a human to solve correctly, but hard enough to keep automated scripts and spam bots out.') .'</p>';
32 $output .= '<p>'. t('Note that the CAPTCHA module interacts with page caching (see <a href="!performancesettings">performance settings</a>). Because the challenge should be unique for each generated form, the caching of the page it appears on is prevented. Make sure that these forms do not appear on too many pages or you will lose much caching efficiency. For example, if you put a CAPTCHA on the user login block, which typically appears on each page for anonymous visitors, caching will practically be disabled. The comment submission forms are another example. In this case you should set the "%commentlocation" to "%separatepage" in the comment settings of the relevant <a href="!contenttypes">content types</a> for better caching efficiency.' ,
33 array(
34 '!performancesettings' => url('admin/settings/performance'),
35 '%commentlocation' => t('Location of comment submission form'),
36 '%separatepage' => t('Display on separate page'),
37 '!contenttypes' => url('admin/content/types'),
38 )
39 ) .'</p>';
40 $output .= '<p>'. t('CAPTCHA is a trademark of Carnegie Mellon University.') .'</p>';
41 return $output;
42 case 'admin/user/captcha':
43 case 'admin/user/captcha/captcha':
44 case 'admin/user/captcha/captcha/settings':
45 $output = '<p>'. t('A CAPTCHA can be added to virtually each Drupal form. Some default forms are already provided in the form list, but arbitrary forms can be easily added and managed when the option "%adminlinks" is enabled.',
46 array('%adminlinks' => t('Add CAPTCHA administration links to forms'))) .'</p>';
47 $output .= '<p>'. t('Users with the "%skipcaptcha" <a href="@perm">permission</a> won\'t be offered a challenge. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a protected form, be sure to do it as a user without the "%skipcaptcha" permission (e.g. as anonymous user).',
48 array('%skipcaptcha' => t('skip CAPTCHA'), '@perm' => url('admin/user/permissions'))) .'</p>';
49 return $output;
50 }
51 }
52
53 /**
54 * Implementation of hook_menu().
55 */
56 function captcha_menu() {
57 $items = array();
58 // main configuration page of the basic CAPTCHA module
59 $items['admin/user/captcha'] = array(
60 'title' => 'CAPTCHA',
61 'description' => 'Administer how and where CAPTCHAs are used.',
62 'file' => 'captcha.admin.inc',
63 'page callback' => 'drupal_get_form',
64 'page arguments' => array('captcha_admin_settings'),
65 'access arguments' => array('administer CAPTCHA settings'),
66 'type' => MENU_NORMAL_ITEM,
67 );
68 // the default local task (needed when other modules want to offer
69 // alternative CAPTCHA types and their own configuration page as local task)
70 $items['admin/user/captcha/captcha'] = array(
71 'title' => 'CAPTCHA',
72 'access arguments' => array('administer CAPTCHA settings'),
73 'type' => MENU_DEFAULT_LOCAL_TASK,
74 'weight' => -20,
75 );
76 $items['admin/user/captcha/captcha/settings'] = array(
77 'title' => 'General settings',
78 'access arguments' => array('administer CAPTCHA settings'),
79 'type' => MENU_DEFAULT_LOCAL_TASK,
80 'weight' => 0,
81 );
82 $items['admin/user/captcha/captcha/examples'] = array(
83 'title' => 'Examples',
84 'description' => 'An overview of the available challenge types with examples.',
85 'file' => 'captcha.admin.inc',
86 'page callback' => 'drupal_get_form',
87 'page arguments' => array('captcha_examples', 5, 6),
88 'access arguments' => array('administer CAPTCHA settings'),
89 'type' => MENU_LOCAL_TASK,
90 'weight' => 5,
91 );
92 $items['admin/user/captcha/captcha/captcha_point'] = array(
93 'title' => 'CAPTCHA point administration',
94 'file' => 'captcha.admin.inc',
95 'page callback' => 'captcha_point_admin',
96 'page arguments' => array(5, 6),
97 'access arguments' => array('administer CAPTCHA settings'),
98 'type' => MENU_CALLBACK,
99 );
100 return $items;
101 }
102
103 /**
104 * Implementation of hook_perm().
105 */
106 function captcha_perm() {
107 return array('administer CAPTCHA settings', 'skip CAPTCHA');
108 }
109
110 /**
111 * Implementation of hook_requirements().
112 */
113 function captcha_requirements($phase) {
114 $requirements = array();
115 $t = get_t();
116 if ($phase == 'runtime') {
117 // show the wrong response counter in the status report
118 $requirements['captcha_wrong_response_counter'] = array(
119 'title' => $t('CAPTCHA'),
120 'value' => format_plural(
121 variable_get('captcha_wrong_response_counter', 0),
122 'Already 1 blocked form submission',
123 'Already @count blocked form submissions'
124 ),
125 'severity' => REQUIREMENT_INFO,
126 );
127 }
128 return $requirements;
129 }
130
131 /**
132 * Implementation of hook_theme().
133 */
134 function captcha_theme() {
135 return array(
136 'captcha_admin_settings_captcha_points' => array(
137 'arguments' => array('form' => NULL),
138 ),
139 'captcha' => array(
140 'arguments' => array('element' => NULL),
141 ),
142 );
143 }
144
145 /**
146 * Implementation of hook_cron().
147 *
148 * Remove old entries from captcha_sessions table.
149 */
150 function captcha_cron() {
151 // remove challenges older than 1 day
152 db_query('DELETE FROM {captcha_sessions} WHERE timestamp < %d', time() - 60*60*24);
153 }
154
155
156 /**
157 * Implementation of hook_elements().
158 */
159 function captcha_elements() {
160 // Define the CAPTCHA form element with default properties.
161 $captcha_element = array(
162 '#input' => TRUE,
163 '#process' => array('captcha_process'),
164 // The type of challenge: e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image', ...
165 '#captcha_type' => 'default',
166 '#default_value' => '',
167 // CAPTCHA in admin mode: presolve the CAPTCHA and always show it (despite previous successful responses).
168 '#captcha_admin_mode' => FALSE,
169 // The default CAPTCHA validation function.
170 // TODO: should this be a single string or an array of strings (combined in OR fashion)?
171 '#captcha_validate' => 'captcha_validate_strict_equality',
172 );
173 // Override the default CAPTCHA validation function for case insensitive validation.
174 // TODO: shouldn't this be done somewhere else, e.g. in form_alter?
175 if (CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE == variable_get('captcha_default_validation', CAPTCHA_DEFAULT_VALIDATION_CASE_INSENSITIVE)) {
176 $captcha_element['#captcha_validate'] = 'captcha_validate_case_insensitive_equality';
177 }
178 return array('captcha' => $captcha_element);
179 }
180
181 /**
182 * Process callback for CAPTCHA form element.
183 */
184 function captcha_process($element, $edit, &$form_state, $complete_form) {
185 module_load_include('inc', 'captcha');
186
187 // Prevent caching of the page with CAPTCHA elements.
188 // This needs to be done even if the CAPTCHA will be ommitted later:
189 // other untrusted users should not get a cached page when
190 // the current untrusted user can skip the current CAPTCHA.
191 global $conf;
192 $conf['cache'] = FALSE;
193
194 // Retrieve CAPTCHA session ID from posted data or generate it, if not available.
195 $this_form_id = $complete_form['form_id']['#value'];
196 // Previously $element['#post']['form_id'] and $element['#post']['captcha_sid']
197 // were used here, but those entry are not available in node preview situations so
198 // we use $form_state['clicked_button']['#post']['form_id'] and
199 // $form_state['clicked_button']['#post']['captcha_sid'] instead.
200 $posted_form_id = (isset($form_state['clicked_button']['#post']['form_id']) ? $form_state['clicked_button']['#post']['form_id'] : NULL);
201 if ($this_form_id == $posted_form_id && isset($form_state['clicked_button']['#post']['captcha_sid'])) {
202 $captcha_sid = $form_state['clicked_button']['#post']['captcha_sid'];
203 } else {
204 // Generate new CAPTCHA session.
205 $captcha_sid = _captcha_generate_captcha_session($this_form_id, CAPTCHA_STATUS_UNSOLVED);
206 }
207
208 // Store CAPTCHA session ID as hidden field.
209 $element['captcha_sid'] = array(
210 '#type' => 'hidden',
211 '#value' => $captcha_sid,
212 );
213
214 // Get implementing module and challenge for CAPTCHA.
215 list($captcha_type_module, $captcha_type_challenge) = _captcha_parse_captcha_type($element['#captcha_type']);
216 if (_captcha_required_for_user($captcha_sid, $this_form_id) || $element['#captcha_admin_mode']) {
217 // Generate a CAPTCHA and its solution
218 // (note that the CAPTCHA session ID is given as third argument).
219 $captcha = module_invoke($captcha_type_module, 'captcha', 'generate', $captcha_type_challenge, $captcha_sid);
220 if (!$captcha) {
221 // The selected module returned nothing, maybe it is disabled or it's wrong, we should watchdog that and then quit.
222 watchdog('CAPTCHA',
223 'CAPTCHA problem: hook_captcha() of module %module returned nothing when trying to retrieve challenge type %type for form %form_id.',
224 array('%type' => $captcha_type_challenge, '%module' => $captcha_type_module, '%form_id' => $this_form_id),
225 WATCHDOG_ERROR);
226 return $element;
227 }
228 // Add form elements from challenge as children to CAPTCHA form element.
229 $element['captcha_widgets'] = $captcha['form'];
230
231 // Add a validation callback for the CAPTCHA form element (when not in admin mode).
232 if (!$element['#captcha_admin_mode']) {
233 $element['#element_validate'] = array('captcha_validate');
234 }
235
236 // Set a custom CAPTCHA validate function if requested.
237 if (isset($captcha['captcha_validate'])) {
238 $element['#captcha_validate'] = $captcha['captcha_validate'];
239 }
240
241 // Add pre_render callback for additional CAPTCHA processing.
242 $element['#pre_render'] = array('captcha_pre_render_process');
243
244 }
245
246 // Store information for usage in the validation and pre_render phase.
247 $element['#captcha_info'] = array(
248 'form_id' => $this_form_id,
249 'module' => $captcha_type_module,
250 'type' => $captcha_type_challenge,
251 'captcha_sid' => $captcha_sid,
252 'solution' => $captcha['solution'],
253 );
254
255 return $element;
256 }
257
258
259 /**
260 * Theme function for a CAPTCHA element.
261 *
262 * Render it in a fieldset if a description of the CAPTCHA
263 * is available. Render it as is otherwise.
264 */
265 function theme_captcha($element) {
266 if (!empty($element['#description']) && isset($element['captcha_widgets'])) {
267 $fieldset = array(
268 '#type' => 'fieldset',
269 '#title' => t('CAPTCHA'),
270 '#description' => $element['#description'],
271 '#children' => $element['#children'],
272 '#attributes' => array('class' => 'captcha'),
273 );
274 return theme('fieldset', $fieldset);
275 }
276 else {
277 return '<div class="captcha">'. $element['#children'] .'</div>';
278 }
279 }
280
281
282 /**
283 * Implementation of hook_form_alter().
284 *
285 * This function adds a CAPTCHA to forms for untrusted users if needed and adds
286 * CAPTCHA administration links for site administrators if this option is enabled.
287 */
288 function captcha_form_alter(&$form, $form_state, $form_id) {
289
290 if (arg(0) != 'admin' || variable_get('captcha_allow_on_admin_pages', FALSE)) {
291
292 module_load_include('inc', 'captcha');
293
294 if (!user_access('skip CAPTCHA')) {
295 // Visitor does not have permission to skip the CAPTCHA
296
297 // Get CAPTCHA type and module for given form_id.
298 $captcha_point = captcha_get_form_id_setting($form_id);
299 if ($captcha_point && $captcha_point->type) {
300 module_load_include('inc', 'captcha');
301 # Build CAPTCHA form element.
302 $captcha_element = array(
303 '#type' => 'captcha',
304 '#captcha_type' => $captcha_point->module .'/'. $captcha_point->type,
305 );
306 // Add a CAPTCHA description if required.
307 if (variable_get('captcha_add_captcha_description', TRUE)) {
308 $captcha_element['#description'] = _captcha_get_description();
309 }
310
311 # Get placement in form and insert in form.
312 $captcha_placement = _captcha_get_captcha_placement($form_id, $form);
313 _captcha_insert_captcha_element($form, $captcha_placement, $captcha_element);
314
315 }
316 }
317 else if (user_access('administer CAPTCHA settings') && variable_get('captcha_administration_mode', FALSE)) {
318 $captcha_point = captcha_get_form_id_setting($form_id);
319 // For administrators: show CAPTCHA info and offer link to configure it
320 $captcha_element = array(
321 '#type' => 'fieldset',
322 '#title' => t('CAPTCHA'),
323 '#collapsible' => TRUE,
324 '#collapsed' => TRUE,
325 );
326 if ($captcha_point !== NULL && $captcha_point->type) {
327 $captcha_element['#title'] = t('CAPTCHA: challenge "@type" enabled', array('@type' => $captcha_point->type));
328 $captcha_element['#description'] = t('Untrusted users will see a CAPTCHA here (!settings).',
329 array('!settings' => l(t('general CAPTCHA settings'), 'admin/user/captcha'))
330 );
331 $captcha_element['challenge'] = array(
332 '#type' => 'item',
333 '#title' => t('Enabled challenge'),
334 '#value' => t('"@type" by module "@module" (!change, !disable)', array(
335 '@type' => $captcha_point->type,
336 '@module' => $captcha_point->module,
337 '!change' => l(t('change'), "admin/user/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination())),
338 '!disable' => l(t('disable'), "admin/user/captcha/captcha/captcha_point/$form_id/disable", array('query' => drupal_get_destination())),
339 )),
340 );
341 // Add an example challenge with solution.
342 // This does not work with the reCAPTCHA and Egglue challenges as
343 // discussed in http://drupal.org/node/487032 and
344 // http://drupal.org/node/525586. As a temporary workaround, we
345 // blacklist the reCAPTCHA and Egglue challenges and do not show
346 // an example challenge.
347 // TODO: Once the issues mentioned above are fixed, this workaround
348 // should be removed.
349 if ($captcha_point->module != 'recaptcha' && $captcha_point->module != 'egglue_captcha') {
350 $captcha_element['example'] = array(
351 '#type' => 'fieldset',
352 '#title' => t('Example'),
353 '#description' => t('This is a pre-solved, non-blocking example of this challenge.'),
354 );
355 $captcha_element['example']['example_captcha'] = array(
356 '#type' => 'captcha',
357 '#captcha_type' => $captcha_point->module .'/'. $captcha_point->type,
358 '#captcha_admin_mode' => TRUE,
359 );
360 }
361 } else {
362 $captcha_element['#title'] = t('CAPTCHA: no challenge enabled');
363 $captcha_element['add_captcha'] = array(
364 '#value' => l(t('Place a CAPTCHA here for untrusted users.'), "admin/user/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination()))
365 );
366
367 }
368 # Get placement in form and insert in form.
369 $captcha_placement = _captcha_get_captcha_placement($form_id, $form);
370 _captcha_insert_captcha_element($form, $captcha_placement, $captcha_element);
371
372 }
373 }
374 }
375
376 /**
377 * CAPTCHA validation function to tests strict equality.
378 * @param $solution the solution of the test.
379 * @param $response the response to the test.
380 * @return TRUE when strictly equal, FALSE otherwise.
381 */
382 function captcha_validate_strict_equality($solution, $response) {
383 return $solution === $response;
384 }
385
386 /**
387 * CAPTCHA validation function to tests case insensitive equality.
388 * @param $solution the solution of the test.
389 * @param $response the response to the test.
390 * @return TRUE when case insensitive equal, FALSE otherwise.
391 */
392 function captcha_validate_case_insensitive_equality($solution, $response) {
393 return strtolower($solution) === strtolower($response);
394 }
395
396 /**
397 * CAPTCHA validation handler.
398 *
399 * This function is placed in the main captcha.module file to make sure that
400 * it is available (even for cached forms, which don't fire
401 * captcha_form_alter(), and subsequently don't include additional include
402 * files).
403 */
404
405 function captcha_validate($element, &$form_state) {
406 $captcha_info = $element['#captcha_info'];
407 $form_id = $captcha_info['form_id'];
408
409 // Get CAPTCHA response.
410 $captcha_response = $form_state['values']['captcha_response'];
411
412 // We use $form_state['clicked_button']['#post']['captcha_sid']
413 // instead of $form_state['values']['captcha_sid'] because the latter
414 // contains the captcha_sid associated to the 'newly' generated element,
415 // while the former contains the captcha_sid of the posted form.
416 // In most cases both will be the same because of persistence.
417 // However, they will differ when the life span of the CAPTCHA session
418 // does not equal the life span of a multipage form and then we have to
419 // pick the right one.
420 $csid = $form_state['clicked_button']['#post']['captcha_sid'];
421
422 $solution = db_result(db_query('SELECT solution FROM {captcha_sessions} WHERE csid = %d AND status = %d', $csid, CAPTCHA_STATUS_UNSOLVED));
423
424 if ($solution === FALSE) {
425 // Unknown challenge_id.
426 form_set_error('captcha', t('CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.'));
427 watchdog('CAPTCHA',
428 'CAPTCHA validation error: unknown CAPTCHA session ID (%csid).',
429 array('%csid' => var_export($csid, TRUE)),
430 WATCHDOG_ERROR);
431 }
432 else {
433 // Get CAPTCHA validate function or fall back on strict equality.
434 $captcha_validate = $element['#captcha_validate'];
435 if (!function_exists($captcha_validate)) {
436 $captcha_validate = 'captcha_validate_strict_equality';
437 }
438 // Check the response with the CAPTCHA validation function.
439 // Apart from the traditional expected $solution and received $response,
440 // we also provide the CAPTCHA $element and $form_state arrays for more advanced use cases.
441 if ($captcha_validate($solution, $captcha_response, $element, $form_state)) {
442 // Correct answer.
443 $_SESSION['captcha_success_form_ids'][$form_id] = $form_id;
444 // Record success.
445 db_query("UPDATE {captcha_sessions} SET status=%d, attempts=attempts+1 WHERE csid=%d", CAPTCHA_STATUS_SOLVED, $csid);
446 }
447 else {
448 // Wrong answer.
449 db_query("UPDATE {captcha_sessions} SET attempts=attempts+1 WHERE csid=%d", $csid);
450 // set form error
451 form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
452 // update wrong response counter
453 variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1);
454 // log to watchdog if needed
455 if (variable_get('captcha_log_wrong_responses', FALSE)) {
456 watchdog('CAPTCHA',
457 '%form_id post blocked by CAPTCHA module: challenge "%challenge" (by module "%module"), user answered "%response", but the solution was "%solution".',
458 array('%form_id' => $form_id,
459 '%response' => $captcha_response, '%solution' => $solution,
460 '%challenge' => $captcha_info['type'], '%module' => $captcha_info['module'],
461 ),
462 WATCHDOG_NOTICE);
463 }
464 // If CAPTCHA was on a login form: stop validating, quit the current request
465 // and forward to the current page (like a reload) to prevent loging in.
466 // We do that because the log in procedure, which happens after
467 // captcha_validate(), does not check error conditions of extra form
468 // elements like the CAPTCHA.
469 if ($form_id == 'user_login' || $form_id == 'user_login_block') {
470 drupal_goto($_GET['q']);
471 }
472 }
473 }
474 }
475
476 /**
477 * Pre-render callback for additional processing of a CAPTCHA form element.
478 *
479 * This encompasses tasks that should happen after the general FAPI processing
480 * (building, submission and validation) but before rendering (e.g. storing the solution).
481 *
482 * @param $element the CAPTCHA form element
483 * @return the manipulated element
484 */
485 function captcha_pre_render_process($element) {
486 // Get form and CAPTCHA information.
487 $captcha_info = $element['#captcha_info'];
488 $form_id = $captcha_info['form_id'];
489 $captcha_sid = (int)($captcha_info['captcha_sid']);
490 // Check if CAPTCHA is still required.
491 // This check is done in a first phase during the element processing
492 // (@see captcha_process), but it is also done here for better support
493 // of multi-page forms. Take previewing a node submission for example:
494 // when the challenge is solved correctely on preview, the form is still
495 // not completely submitted, but the CAPTCHA can be skipped.
496 if (_captcha_required_for_user($captcha_sid, $form_id) || $element['#captcha_admin_mode']) {
497 // Update captcha_sessions table: store the solution of the generated CAPTCHA.
498 _captcha_update_captcha_session($captcha_sid, $captcha_info['solution']);
499
500 // Handle the response field if it is available and if it is a textfield.
501 if (isset($element['captcha_widgets']['captcha_response']['#type']) && $element['captcha_widgets']['captcha_response']['#type'] == 'textfield') {
502 // Before rendering: presolve an admin mode challenge or
503 // empty the value of the captcha_response form item.
504 $value = $element['#captcha_admin_mode'] ? $captcha_info['solution'] : '';
505 $element['captcha_widgets']['captcha_response']['#value'] = $value;
506 }
507 }
508 else {
509 // Remove CAPTCHA widgets from form.
510 unset($element['captcha_widgets']);
511 }
512
513 return $element;
514 }
515
516 /**
517 * Default implementation of hook_captcha().
518 */
519 function captcha_captcha($op, $captcha_type = '') {
520 switch ($op) {
521 case 'list':
522 return array('Math');
523 break;
524
525 case 'generate':
526 if ($captcha_type == 'Math') {
527 $result = array();
528 $answer = mt_rand(1, 20);
529 $x = mt_rand(1, $answer);
530 $y = $answer - $x;
531 $result['solution'] = "$answer";
532 // Build challenge widget.
533 // Note that we also use t() for the math challenge itself. This makes
534 // it possible to 'rephrase' the challenge a bit through localization
535 // or string overrides.
536 $result['form']['captcha_response'] = array(
537 '#type' => 'textfield',
538 '#title' => t('Math question'),
539 '#description' => t('Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.'),
540 '#field_prefix' => t('@x + @y = ', array('@x' => $x, '@y' => $y)),
541 '#size' => 4,
542 '#maxlength' => 2,
543 '#required' => TRUE,
544 );
545 return $result;
546 }
547 elseif ($captcha_type == 'Test') {
548 // This challenge is not visible through the administrative interface
549 // as it is not listed in captcha_captcha('list'),
550 // but it is meant for debugging and testing purposes.
551 // TODO for Drupal 7 version: This should be done with a mock module,
552 // but Drupal 6 does not support this (mock modules can not be hidden).
553 $result = array(
554 'solution' => 'Test 123',
555 'form' => array(),
556 );
557 $result['form']['captcha_response'] = array(
558 '#type' => 'textfield',
559 '#title' => t('Test one two three'),
560 '#required' => TRUE,
561 );
562 return $result;
563 }
564 break;
565 }
566 }

  ViewVC Help
Powered by ViewVC 1.1.2