~spreadubuntu/spreadubuntu/devel-drupal6

« back to all changes in this revision

Viewing changes to modules/captcha/text_captcha/text_captcha.admin.inc

  • Committer: ruben
  • Date: 2009-06-08 09:38:49 UTC
  • Revision ID: ruben@captive-20090608093849-s1qtsyctv2vwp1x1
SpreadUbuntu moving to Drupal6. Based on ubuntu-drupal theme and adding our modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
// $Id: text_captcha.admin.inc,v 1.1 2008/01/04 14:29:58 soxofaan Exp $
 
3
 
 
4
/**
 
5
 * Administration form
 
6
 */
 
7
function text_captcha_settings_form() {
 
8
  $form = array();
 
9
 
 
10
  // radio buttons for selecting the kind of words to use
 
11
  $form['text_captcha_words'] = array(
 
12
    '#type' => 'radios',
 
13
    '#title' => t('Kind of words to use in the phrase'),
 
14
    '#options' => array(
 
15
      TEXT_CAPTCHA_GENERATE_NONSENSE_WORDS => t('Generate nonsense random words.'),
 
16
      TEXT_CAPTCHA_USER_DEFINED_WORDS => t('Use user defined words.')
 
17
    ),
 
18
    '#default_value' => variable_get('text_captcha_words', TEXT_CAPTCHA_GENERATE_NONSENSE_WORDS),
 
19
  );
 
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)),
 
26
  );
 
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),
 
32
    '#size' => 2,
 
33
    '#maxlength' => 2,
 
34
  );
 
35
 
 
36
  $form['#validate'][] = 'text_captcha_settings_form_validate';
 
37
  return system_settings_form($form);
 
38
}
 
39
 
 
40
/**
 
41
 * Validate function of the administration form
 
42
 */
 
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)
 
50
        )
 
51
      );
 
52
    }
 
53
  }
 
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.'));
 
58
  }
 
59
}