I have this code that gets me out some checkboxes with the watchdog severities:
/**
* Checkbox for errors, alerts, e.t.c
*/
foreach (watchdog_severity_levels() as $severity => $description) {
$key = 'severity_errors' . $severity;
$form['severity_errors'][$key] = array(
'#type' => 'checkbox',
'#title' => t('@description', array('@description' => drupal_ucfirst($description))),
'#default_value' => variable_get($key, array()),
);
return system_settings_form($form);
}
I set this $key in my code as:
$key = array_filter(variable_get($key,array()));
I think this set is wrong as the drupal gets me out error. After that set of $key I call it with the following foreach statement could someone help me with that thing?
foreach ($key as $value) {
if ($value == 'warning') {
blablblablabla....
}
elseif ($value == 'notice') {
blablablbalbal....
}
}
Using your logic, you would store following keys
severity_errors0
,severity_errors1
,severity_errors2
, ... in thevariable
table because the$severity
key of your foreach is just the index.Wouldn't it be easier to store an array of selected severity levels as one entry in the variable table?
Here some example code which does the job for you:
Now to retrieve the selected severity levels, you do something like this:
You need to add some debugging to figure out where exactly it's going wrong. Would recommend using dpm() to inspect the code at some of the key stages like 1) after building the form, 2) when you assign the array to $key and 3) before starting the final foreach loop so you can pinpoint where it's going wrong and address it.