function captcha_get_form_id_setting in CAPTCHA 7
Same name and namespace in other branches
- 8 captcha.inc \captcha_get_form_id_setting()
- 6.2 captcha.inc \captcha_get_form_id_setting()
Get the CAPTCHA setting for a given form_id.
Parameters
string $form_id: the form_id to query for
bool $symbolic: flag to return as (symbolic) strings instead of object.
Return value
NULL if no setting is known or a captcha_point object with fields 'module' and 'captcha_type'. If argument $symbolic is true, returns (symbolic) as 'none', 'default' or in the form 'captcha/Math'.
4 calls to captcha_get_form_id_setting()
- CaptchaAdminTestCase::assertCaptchaSetting in ./
captcha.test - Helper function for checking CAPTCHA setting of a form.
- CaptchaAdminTestCase::testCaptchaPointSettingGetterAndSetter in ./
captcha.test - Test the CAPTCHA point setting getter/setter.
- captcha_form_alter in ./
captcha.module - Implements of hook_form_alter().
- captcha_point_admin_form in ./
captcha.admin.inc - Admin form.
File
- ./
captcha.inc, line 84 - General CAPTCHA functionality and helper functions.
Code
function captcha_get_form_id_setting($form_id, $symbolic = FALSE) {
// Fetch setting from database.
if (module_exists('ctools')) {
ctools_include('export');
$object = ctools_export_load_object('captcha_points', 'names', array(
$form_id,
));
$captcha_point = array_pop($object);
}
else {
$result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id", array(
':form_id' => $form_id,
));
$captcha_point = $result
->fetchObject();
}
// If no setting is available in database for the given form,
// but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway.
if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE)) {
$captcha_point = (object) array(
'captcha_type' => 'default',
);
}
// Handle (default) settings and symbolic mode.
if (!$captcha_point) {
$captcha_point = NULL;
}
elseif (!empty($captcha_point->captcha_type) && $captcha_point->captcha_type == 'default') {
if (!$symbolic) {
list($module, $type) = explode('/', variable_get('captcha_default_challenge', 'captcha/Math'));
$captcha_point->module = $module;
$captcha_point->captcha_type = $type;
}
else {
$captcha_point = 'default';
}
}
elseif (empty($captcha_point->module) && empty($captcha_point->captcha_type) && $symbolic) {
$captcha_point = 'none';
}
elseif ($symbolic) {
$captcha_point = $captcha_point->module . '/' . $captcha_point->captcha_type;
}
return $captcha_point;
}