function captcha_set_form_id_setting in CAPTCHA 7
Same name and namespace in other branches
- 8 captcha.inc \captcha_set_form_id_setting()
- 6.2 captcha.inc \captcha_set_form_id_setting()
Helper function for adding/updating a CAPTCHA point.
Parameters
string $form_id: the form ID to configure.
string $captcha_type: the setting for the given form_id, can be:
- 'none' to disable CAPTCHA,
- 'default' to use the default challenge type
- NULL to remove the entry for the CAPTCHA type
- something of the form 'image_captcha/Image'
- an object with attributes $captcha_type->module and $captcha_type->captcha_type
18 calls to captcha_set_form_id_setting()
- CaptchaAdminTestCase::testCaptchaPlacementCacheClearing in ./
captcha.test - Test the CAPTCHA placement clearing.
- CaptchaAdminTestCase::testCaptchaPointSettingGetterAndSetter in ./
captcha.test - Test the CAPTCHA point setting getter/setter.
- CaptchaAdminTestCase::testUntrustedUserPosting in ./
captcha.test - CaptchaAdminTestCase::testXssOnCaptchaDescription in ./
captcha.test - Test XSS vulnerability on CAPTCHA description.
- CaptchaPersistenceTestCase::setUpPersistence in ./
captcha.test - Set up the persistence and CAPTCHA settings.
File
- ./
captcha.inc, line 22 - General CAPTCHA functionality and helper functions.
Code
function captcha_set_form_id_setting($form_id, $captcha_type) {
// Handle 'none'.
if ($captcha_type == 'none') {
db_merge('captcha_points')
->key(array(
'form_id' => $form_id,
))
->fields(array(
'module' => NULL,
'captcha_type' => NULL,
))
->execute();
}
elseif ($captcha_type == 'default') {
db_merge('captcha_points')
->key(array(
'form_id' => $form_id,
))
->fields(array(
'module' => NULL,
'captcha_type' => 'default',
))
->execute();
}
elseif ($captcha_type == NULL) {
db_delete('captcha_points')
->condition('form_id', $form_id)
->execute();
}
elseif (is_object($captcha_type) && !empty($captcha_type->module) && !empty($captcha_type->captcha_type)) {
db_merge('captcha_points')
->key(array(
'form_id' => $form_id,
))
->fields(array(
'module' => $captcha_type->module,
'captcha_type' => $captcha_type->captcha_type,
))
->execute();
}
elseif (is_string($captcha_type) && substr_count($captcha_type, '/') == 1) {
list($module, $type) = explode('/', $captcha_type);
db_merge('captcha_points')
->key(array(
'form_id' => $form_id,
))
->fields(array(
'module' => $module,
'captcha_type' => $type,
))
->execute();
}
else {
drupal_set_message(t('Failed to set a CAPTCHA type for form %form_id: could not interpret value "@captcha_type"', array(
'%form_id' => $form_id,
'@captcha_type' => (string) $captcha_type,
)), 'warning');
}
}