function captcha_admin_settings_submit in CAPTCHA 7
Same name and namespace in other branches
- 5.3 captcha.module \captcha_admin_settings_submit()
- 6.2 captcha.admin.inc \captcha_admin_settings_submit()
- 6 captcha.admin.inc \captcha_admin_settings_submit()
Submission function for captcha_admin_settings form.
File
- ./
captcha.admin.inc, line 311 - Functionality and helper functions for CAPTCHA administration.
Code
function captcha_admin_settings_submit($form, &$form_state) {
variable_set('captcha_administration_mode', $form_state['values']['captcha_administration_mode']);
variable_set('captcha_allow_on_admin_pages', $form_state['values']['captcha_allow_on_admin_pages']);
variable_set('captcha_default_challenge', $form_state['values']['captcha_default_challenge']);
variable_set('captcha_default_challenge_on_nonlisted_forms', $form_state['values']['captcha_default_challenge_on_nonlisted_forms']);
// Load languages for configurable texts.
if (module_exists('locale')) {
$langs = locale_language_list();
}
// Process CAPTCHA points.
if (isset($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'])) {
// Load existing data.
$captcha_points = captcha_get_captcha_points();
foreach ($form_state['values']['captcha_form_id_overview']['captcha_captcha_points'] as $captcha_point_form_id => $data) {
// If this is an in-code captcha point and its settings are unchanged,
// don't save to the database.
if (module_exists('ctools') && isset($captcha_points[$captcha_point_form_id])) {
// Parse module and captcha_type from submitted values.
if (is_string($data['captcha_type']) && substr_count($data['captcha_type'], '/') == 1) {
list($module, $captcha_type) = explode('/', $data['captcha_type']);
}
else {
$module = '';
$captcha_type = $data['captcha_type'];
}
$point = $captcha_points[$captcha_point_form_id];
if ($point->export_type & EXPORT_IN_CODE && !($point->export_type & EXPORT_IN_DATABASE) && $point->module == $module && $point->captcha_type == $captcha_type) {
continue;
}
}
captcha_set_form_id_setting($captcha_point_form_id, $data['captcha_type']);
}
}
// Add new CAPTCHA point?
$captcha_point_form_id = $form_state['values']['captcha_form_id_overview']['captcha_new_captcha_point']['form_id'];
if (!empty($captcha_point_form_id)) {
$captcha_type = $form_state['values']['captcha_form_id_overview']['captcha_new_captcha_point']['captcha_type'];
captcha_set_form_id_setting($captcha_point_form_id, $captcha_type);
drupal_set_message(t('Added CAPTCHA point.'), 'status');
}
// Error message.
if (module_exists('locale')) {
foreach ($langs as $lang_code => $lang_name) {
$description = $form_state['values']['captcha_error_message_' . $lang_code];
if ($description) {
variable_set('captcha_error_message_' . $lang_code, $description);
}
else {
variable_del('captcha_error_message_' . $lang_code);
drupal_set_message(t('Reset of error message for language %language.', array(
'%language' => $lang_name,
)), 'status');
}
}
}
else {
$description = $form_state['values']['captcha_error_message'];
if ($description) {
variable_set('captcha_error_message', $description);
}
else {
variable_del('captcha_error_message');
drupal_set_message(t('Reset of error message.'), 'status');
}
}
// CAPTCHA description stuff.
variable_set('captcha_add_captcha_description', $form_state['values']['captcha_add_captcha_description']);
// Save (or reset) the CAPTCHA descriptions.
if (module_exists('locale')) {
foreach ($langs as $lang_code => $lang_name) {
$description = $form_state['values']["captcha_description_{$lang_code}"];
if ($description) {
variable_set("captcha_description_{$lang_code}", $description);
}
else {
variable_del("captcha_description_{$lang_code}");
drupal_set_message(t('Reset of CAPTCHA description for language %language.', array(
'%language' => $lang_name,
)), 'status');
}
}
}
else {
$description = $form_state['values']['captcha_description'];
if ($description) {
variable_set('captcha_description', $description);
}
else {
variable_del('captcha_description');
drupal_set_message(t('Reset of CAPTCHA description.'), 'status');
}
}
variable_set('captcha_default_validation', $form_state['values']['captcha_default_validation']);
variable_set('captcha_persistence', $form_state['values']['captcha_persistence']);
variable_set('captcha_enable_stats', $form_state['values']['captcha_enable_stats']);
variable_set('captcha_log_wrong_responses', $form_state['values']['captcha_log_wrong_responses']);
drupal_set_message(t('The CAPTCHA settings have been saved.'), 'status');
}