You are here

function math_captcha_settings_form_validate in CAPTCHA Pack 6

Same name and namespace in other branches
  1. 5 math_captcha/math_captcha.module \math_captcha_settings_form_validate()
  2. 7 math_captcha/math_captcha.admin.inc \math_captcha_settings_form_validate()

Validation function for Math CAPTCHA settings form

1 string reference to 'math_captcha_settings_form_validate'
math_captcha_settings_form in math_captcha/math_captcha.admin.inc
Math CAPTCHA settings form

File

math_captcha/math_captcha.admin.inc, line 91

Code

function math_captcha_settings_form_validate($form, &$form_state) {

  // check enabled challenges
  if (count(array_filter($form_state['values']['math_captcha_enabled_challenges'])) < 1) {
    form_set_error('math_captcha_enabled_challenges', t('You should select at least one type of math challenges.'));
  }

  // check argmax's
  $argmaxs = array(
    'math_captcha_addition_argmax',
    'math_captcha_subtraction_argmax',
    'math_captcha_multiplication_argmax',
  );
  foreach ($argmaxs as $argmax) {
    if (!is_numeric($form_state['values'][$argmax])) {
      form_set_error($argmax, t('Maximum value should be an integer.'));
    }
    else {
      $form_state['values'][$argmax] = intval($form_state['values'][$argmax]);
      if ($form_state['values'][$argmax] < 2) {
        form_set_error($argmax, t('Maximum value should be an integer and at least 2'));
      }
    }
  }
}