You are here

function image_captcha_settings_form_validate in CAPTCHA 7

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

Validation function for image_captcha configuration form.

1 string reference to 'image_captcha_settings_form_validate'
image_captcha_settings_form in image_captcha/image_captcha.admin.inc
Configuration form for image_captcha.

File

image_captcha/image_captcha.admin.inc, line 333
Functions for administration/settings interface.

Code

function image_captcha_settings_form_validate($form, &$form_state) {

  // Check image_captcha_image_allowed_chars for spaces.
  if (preg_match('/\\s/', $form_state['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.'));
  }
  if (!isset($form['image_captcha_font_settings']['no_ttf_support'])) {

    // Check the selected fonts.
    // Filter the image_captcha fonts array to pick out the selected ones.
    $fonts = array_filter($form_state['values']['image_captcha_fonts']);
    if (count($fonts) < 1) {
      form_set_error('image_captcha_fonts', t('You need to select at least one font.'));
    }
    if ($form_state['values']['image_captcha_fonts']['BUILTIN']) {

      // With the built in font, only latin2 characters should be used.
      if (preg_match('/[^a-zA-Z0-9]/', $form_state['values']['image_captcha_image_allowed_chars'])) {
        form_set_error('image_captcha_image_allowed_chars', t('The built-in font only supports Latin2 characters. Only use "a" to "z" and numbers.'));
      }
    }
    list($readable_fonts, $problem_fonts) = _image_captcha_check_fonts($fonts);
    if (count($problem_fonts) > 0) {
      form_set_error('image_captcha_fonts', t('The following fonts are not readable: %fonts.', array(
        '%fonts' => implode(', ', $problem_fonts),
      )));
    }
  }

  // Check color settings.
  if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_state['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_state['values']['image_captcha_foreground_color'])) {
    form_set_error('image_captcha_foreground_color', t('Text color is not a valid hexadecimal color value.'));
  }
}