You are here

function image_captcha_settings_form_validate in CAPTCHA 6

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. 7 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 204

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.'));
  }

  // check font
  $font = $form_state['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_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.'));
  }
}