我想更改我的复选框
i want to change my checkboxes
我这里有一些复选框,其值为 watchdog_severity:
// Form for the severity checkboxes.
$blabla_severity_levels = variable_get('blabla_severity_levels', array());
// Declare empty options array.
$blabla_severity_options = array();
// Loop through each severity level and push to options array for form.
foreach (watchdog_severity_levels() as $number_select => $severity) {
$blabla_severity_options[$severity] = check_plain(drupal_ucfirst(
$severity));
}
// Generate checkbox list for given severity levels.
$blabla_form['blabla_severity'] = array(
'#type' => 'fieldset',
'#title' => t('Select the severity.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$blabla_form['blabla_severity']['blabla_severity_levels'] = array(
'#type' => 'checkboxes',
'#title' => t('Type of log messages'),
'#options' => $blabla_severity_options,
'#default_value' => array_values($blabla_severity_levels),
'#required' => TRUE,
);
return system_settings_form($blabla_form);
好的,现在我调用函数 severity_levels:
function blabla_check_checkboxes() {
$severity_levels = variable_get('blabla_severity_levels', array());
}
现在,如果只选择信息复选框并导出 $severity_levels
的值,它会让我得到这样的结果:
info (String, 4 characters ) info
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
error (Integer) 0
warning (Integer) 0
notice (Integer) 0
debug (Integer) 0
但我想在我的函数中导出类似这样的东西 blabla_check_checkboxes()
:
info (Integer) 6
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
error (Integer) 0
warning (Integer) 0
notice (Integer) 0
debug (Integer) 0
其中 6 是 drupal 严重性信息的数量...
有人可以帮忙解决这个问题吗??
因为您正在使用 system_settings_form_submit - 此函数将仅保存数组键。
您需要找到一种解决方法,例如使用额外的提交函数或使用包装函数来检索此结构化数组。
在这种情况下,您尝试过度使用复选框的初始范围。
一个解决方案可能是修改您的函数,以便 return 所需的结构:
function blabla_check_checkboxes() {
$orig_severity_levels = watchdog_severity_levels();
$blabla_severity_levels = variable_get('blabla_severity_levels', array());
foreach ($blabla_severity_levels as $level => $name) {
if ((int) $name) {
$blabla_severity_levels[$level] = $orig_severity_levels[$level];
}
}
return $blabla_severity_levels;
}
我这里有一些复选框,其值为 watchdog_severity:
// Form for the severity checkboxes.
$blabla_severity_levels = variable_get('blabla_severity_levels', array());
// Declare empty options array.
$blabla_severity_options = array();
// Loop through each severity level and push to options array for form.
foreach (watchdog_severity_levels() as $number_select => $severity) {
$blabla_severity_options[$severity] = check_plain(drupal_ucfirst(
$severity));
}
// Generate checkbox list for given severity levels.
$blabla_form['blabla_severity'] = array(
'#type' => 'fieldset',
'#title' => t('Select the severity.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$blabla_form['blabla_severity']['blabla_severity_levels'] = array(
'#type' => 'checkboxes',
'#title' => t('Type of log messages'),
'#options' => $blabla_severity_options,
'#default_value' => array_values($blabla_severity_levels),
'#required' => TRUE,
);
return system_settings_form($blabla_form);
好的,现在我调用函数 severity_levels:
function blabla_check_checkboxes() {
$severity_levels = variable_get('blabla_severity_levels', array());
}
现在,如果只选择信息复选框并导出 $severity_levels
的值,它会让我得到这样的结果:
info (String, 4 characters ) info
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
error (Integer) 0
warning (Integer) 0
notice (Integer) 0
debug (Integer) 0
但我想在我的函数中导出类似这样的东西 blabla_check_checkboxes()
:
info (Integer) 6
emergency (Integer) 0
alert (Integer) 0
critical (Integer) 0
error (Integer) 0
warning (Integer) 0
notice (Integer) 0
debug (Integer) 0
其中 6 是 drupal 严重性信息的数量... 有人可以帮忙解决这个问题吗??
因为您正在使用 system_settings_form_submit - 此函数将仅保存数组键。
您需要找到一种解决方法,例如使用额外的提交函数或使用包装函数来检索此结构化数组。
在这种情况下,您尝试过度使用复选框的初始范围。
一个解决方案可能是修改您的函数,以便 return 所需的结构:
function blabla_check_checkboxes() {
$orig_severity_levels = watchdog_severity_levels();
$blabla_severity_levels = variable_get('blabla_severity_levels', array());
foreach ($blabla_severity_levels as $level => $name) {
if ((int) $name) {
$blabla_severity_levels[$level] = $orig_severity_levels[$level];
}
}
return $blabla_severity_levels;
}