You are here

function math_captcha_settings_form_validate in CAPTCHA Pack 5

Same name and namespace in other branches
  1. 6 math_captcha/math_captcha.admin.inc \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

File

math_captcha/math_captcha.module, line 127

Code

function math_captcha_settings_form_validate($form_id, $form_values) {
  if ($form_id == 'math_captcha_settings_form') {

    // check enabled challenges
    if ($form_values['math_captcha_enabled_challenges'][0]) {
      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_values[$argmax])) {
        form_set_error($argmax, t('Maximum value should be an integer.'));
      }
      else {
        if (intval($form_values[$argmax]) < 2) {
          form_set_error($argmax, t('Maximum value should be an integer and at least 2'));
        }
      }
    }
  }
}