You are here

function botcha_admin_settings_submit in BOTCHA Spam Prevention 6

Same name and namespace in other branches
  1. 6.2 botcha.admin.inc \botcha_admin_settings_submit()
  2. 7 botcha.pages.inc \botcha_admin_settings_submit()
  3. 7.2 botcha.admin.inc \botcha_admin_settings_submit()

Submission function for botcha_admin_settings form.

File

./botcha.pages.inc, line 251
Implementation of botcha administration forms.

Code

function botcha_admin_settings_submit($form, &$form_state) {

  // Generate the secret key
  if (empty($form_state['values']['botcha_secret'])) {

    // Generate unique secret for this site
    $secret = botcha_generate_secret_key();
    $form_state['values']['botcha_secret'] = $secret;
    drupal_set_message(t('New BOTCHA secret key have been generated.'));
  }

  // Do what system_settings_form() would do with regular variable fields
  variable_set('botcha_secret', $form_state['values']['botcha_secret']);
  variable_set('botcha_on_captcha_forms', !empty($form_state['values']['botcha_on_captcha_forms']) ? $form_state['values']['botcha_on_captcha_forms'] : FALSE);
  variable_set('botcha_administration_mode', $form_state['values']['botcha_administration_mode']);
  variable_set('botcha_allow_on_admin_pages', $form_state['values']['botcha_allow_on_admin_pages']);
  variable_set('botcha_loglevel', $form_state['values']['botcha_loglevel']);

  // Process BOTCHA points
  if (isset($form_state['values']['botcha_form_id_overview']['botcha_botcha_points'])) {
    foreach ($form_state['values']['botcha_form_id_overview']['botcha_botcha_points'] as $botcha_point_form_id => $data) {
      botcha_set_form_id_setting($botcha_point_form_id, $data['botcha_type']);
    }
  }

  // Add new BOTCHA point?
  $botcha_point_form_id = $form_state['values']['botcha_form_id_overview']['botcha_new_botcha_point']['form_id'];
  if (!empty($botcha_point_form_id)) {
    $botcha_type = $form_state['values']['botcha_form_id_overview']['botcha_new_botcha_point']['botcha_type'];
    botcha_set_form_id_setting($botcha_point_form_id, $botcha_type);
    drupal_set_message(t('Added BOTCHA of type %type for form %form_id.', array(
      '%type' => $botcha_type,
      '%form_id' => $botcha_point_form_id,
    )), 'status');
  }
  drupal_set_message(t('The BOTCHA settings were saved.'), 'status');
}