You are here

function image_captcha_settings_form_validate in CAPTCHA 5.3

Same name and namespace in other branches
  1. 6.2 image_captcha/image_captcha.admin.inc \image_captcha_settings_form_validate()
  2. 6 image_captcha/image_captcha.admin.inc \image_captcha_settings_form_validate()
  3. 7 image_captcha/image_captcha.admin.inc \image_captcha_settings_form_validate()

Validation function for image_captcha configuration form

File

image_captcha/image_captcha.admin.inc, line 217
Implementation of the administration UI of the image CAPTCHA module.

Code

function image_captcha_settings_form_validate($form_id, $form_values) {
  if ($form_id == 'image_captcha_settings_form') {

    // check image_captcha_image_allowed_chars for spaces
    if (preg_match('/\\s/', $form_values['image_captcha_image_allowed_chars'])) {
      form_set_error('image_captcha_image_allowed_chars', t('The list of characters to use should not contain spaces.'));
    }

    // check font
    $font = $form_values['image_captcha_font'];
    if ($font == '0') {
      form_set_error('image_captcha_font', t('You need to select a font'));
    }
    elseif ($font != 'BUILTIN' && (!is_file($font) || !is_readable($font))) {
      form_set_error('image_captcha_font', t('Font does not exist or is not readable.'));
    }

    // check color settings
    if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_values['image_captcha_background_color'])) {
      form_set_error('image_captcha_background_color', t('Background color is not a valid hexadecimal color value.'));
    }
    if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_values['image_captcha_foreground_color'])) {
      form_set_error('image_captcha_foreground_color', t('Text color is not a valid hexadecimal color value.'));
    }
  }
}