You are here

function text_captcha_settings_form_validate in CAPTCHA 5.3

Same name and namespace in other branches
  1. 6 text_captcha/text_captcha.admin.inc \text_captcha_settings_form_validate()

Validate function of the administration form

File

text_captcha/text_captcha.module, line 81
Implementation of a text based CAPTCHA.

Code

function text_captcha_settings_form_validate($form_id, $form_values) {
  if ($form_id == 'text_captcha_settings_form') {
    if ($form_values['text_captcha_words'] == TEXT_CAPTCHA_USER_DEFINED_WORDS) {

      // check if there are at minimum TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM user defined words
      if (count(explode(' ', $form_values['text_captcha_userdefined_words'])) < TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM) {
        form_set_error('text_captcha_userdefined_words', t('You need to enter at least @min words if you want to use user defined words.', array(
          '@min' => TEXT_CAPTCHA_USER_DEFINED_WORD_MINIMUM,
        )));
      }
    }

    // chech text_captcha_word_quantity
    $word_quantity = (int) $form_values['text_captcha_word_quantity'];
    if ($word_quantity < 4 || $word_quantity > 10) {
      form_set_error('text_captcha_word_quantity', t('Number of words in the phrase should be between 4 and 10.'));
    }
  }
}