Index: text_captcha/word_list_captcha/word_list_captcha.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha_pack/text_captcha/word_list_captcha/word_list_captcha.module,v retrieving revision 1.12 diff -u -p -r1.12 word_list_captcha.module --- text_captcha/word_list_captcha/word_list_captcha.module 7 Apr 2008 22:55:03 -0000 1.12 +++ text_captcha/word_list_captcha/word_list_captcha.module 11 Nov 2010 00:31:53 -0000 @@ -78,16 +78,7 @@ function word_list_captcha_captcha($op, '#options' => $options, // extra class needed for additional CSS'ing of the options '#attributes' => array('class' => 'text-captcha-word-list-radios'), - // TODO: the following needs to be ported to Drupal 6, which does not - // support DANGEROUS_SKIP_CHECK anymore - // - // The following entry '#DANGEROUS_SKIP_CHECK' is needed to prevent - // that Drupal checks during validation phase if a submitted option - // is in the list of possible options. (see includes/form.inc) - // The options are randomly generated on each call and consequently - // almost never the same during the generate phase and the validation - // phase. - '#DANGEROUS_SKIP_CHECK' => TRUE, // + '#after_build' => array('_word_list_captcha_validate_response'), '#required' => TRUE, ); // additional text CAPTCHA CSS rules @@ -97,3 +88,25 @@ function word_list_captcha_captcha($op, break; } } + +/** + * #after_build handler for captcha_response element. + * + * Because the options are randomly generated (and consequently almost + * never the same at validation as they were during the initial + * generation), the following #after_build step is used to prevent + * Drupal's validation from rejecting the submitted value with 'An + * illegal choice has been detected' if it does not appear in the new + * set of options. + */ +function _word_list_captcha_validate_response($element, &$form_state) { + if (array_key_exists('#value', $element)) { + if ($value = $element['#value']) { + $options =& $element['#options']; + if (!array_key_exists($value, $options)) { + $options[$value] = $value; + } + } + } + return $element; +}