You are here

function riddler_settings_submit in Captcha Riddler 7

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

Submit the settings form.

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

File

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

Code

function riddler_settings_submit($form, &$form_state) {

  // Delete them all.
  db_delete('riddler_questions')
    ->execute();
  $insert = db_insert('riddler_questions')
    ->fields(array(
    'question',
    'answer',
  ));
  $data = array();
  $values = $form_state['values'];
  foreach (element_children($form['riddler_groups']) as $group) {
    if (stristr($group, 'riddler_group')) {
      $qid = str_replace('riddler_group_', '', $group);

      // Make sure pair is not deleted or empty.
      if (!$values['riddler_delete_' . $qid] && isset($values['riddler_question_' . $qid])) {
        $data[] = array(
          'question' => $values['riddler_question_' . $qid],
          'answer' => $values['riddler_answer_' . $qid],
        );

        // Force call to t() to insert new riddles in the translation database!
        $translation_hack = t(filter_xss($values['riddler_question_' . $qid]));
        $translation_hack = t(filter_xss($values['riddler_answer_' . $qid]));
      }
    }
  }
  foreach ($data as $datum) {
    $insert
      ->values($datum);
  }
  $insert
    ->execute();
  variable_set('riddler_weight', $form_state['values']['riddler_weight']);
  drupal_set_message(t('Riddler settings saved.'), 'status');
}