2
// $Id: text_captcha.admin.inc,v 1.1 2008/01/04 14:29:58 soxofaan Exp $
7
function text_captcha_settings_form() {
10
// radio buttons for selecting the kind of words to use
11
$form['text_captcha_words'] = array(
13
'#title' => t('Kind of words to use in the phrase'),
15
TEXT_CAPTCHA_GENERATE_NONSENSE_WORDS => t('Generate nonsense random words.'),
16
TEXT_CAPTCHA_USER_DEFINED_WORDS => t('Use user defined words.')
18
'#default_value' => variable_get('text_captcha_words', TEXT_CAPTCHA_GENERATE_NONSENSE_WORDS),
20
// textarea for user defined words
21
$form['text_captcha_userdefined_words'] = array(
22
'#type' => 'textarea',
23
'#title' => t('User defined words'),
24
'#default_value' => variable_get('text_captcha_userdefined_words', ''),
25
'#description' => t('Enter a bunch of space separated words (at least @min).', array('@min' => TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM)),
27
// textfield for the number of words in the CAPTCHA phrase
28
$form['text_captcha_word_quantity'] = array(
29
'#type' => 'textfield',
30
'#title' => t('Number of words in the phrase'),
31
'#default_value' => (int) variable_get('text_captcha_word_quantity', 5),
36
$form['#validate'][] = 'text_captcha_settings_form_validate';
37
return system_settings_form($form);
41
* Validate function of the administration form
43
function text_captcha_settings_form_validate($form, &$form_state) {
44
if ($form_state['values']['text_captcha_words'] == TEXT_CAPTCHA_USER_DEFINED_WORDS) {
45
// check if there are at minimum TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM user defined words
46
if (count(explode(' ', $form_state['values']['text_captcha_userdefined_words'])) < TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM) {
47
form_set_error('text_captcha_userdefined_words',
48
t('You need to enter at least @min words if you want to use user defined words.',
49
array('@min' => TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM)
54
// chech text_captcha_word_quantity
55
$word_quantity = (int) $form_state['values']['text_captcha_word_quantity'];
56
if ($word_quantity < 4 || $word_quantity > 10) {
57
form_set_error('text_captcha_word_quantity', t('Number of words in the phrase should be between 4 and 10.'));