You are here

function riddler_settings_validate in Captcha Riddler 7

Same name and namespace in other branches
  1. 6 riddler.module \riddler_settings_validate()

Validate the settings form.

1 string reference to 'riddler_settings_validate'
riddler_settings in ./riddler.module
Settings form definition.

File

./riddler.module, line 169
Adds a question and answer type to the Captcha module.

Code

function riddler_settings_validate($form, &$form_state) {
  $i = 1;
  while (array_key_exists('riddler_question_' . $i, $form_state['values'])) {
    if ($form_state['values']['riddler_question_' . $i] != '' && $form_state['values']['riddler_answer_' . $i] == '') {
      form_set_error('riddler_answer_' . $i, t('Riddle !i is incomplete (answer is missing).', array(
        '!i' => $i,
      )));
    }
    if ($form_state['values']['riddler_question_' . $i] == '' && $form_state['values']['riddler_answer_' . $i] != '') {
      form_set_error('riddler_question_' . $i, t('Riddle !i is incomplete (question is missing).', array(
        '!i' => $i,
      )));
    }

    // Unset any completely empty riddle/answer pairs.
    if ($form_state['values']['riddler_question_' . $i] == '' && $form_state['values']['riddler_answer_' . $i] == '') {
      unset($form_state['values']['riddler_question_' . $i], $form_state['values']['riddler_answer_' . $i]);
    }
    $i++;
  }
}