function views_calc_fields_form_validate in Views Calc 5
Same name and namespace in other branches
- 6.3 views_calc.module \views_calc_fields_form_validate()
- 6 views_calc.module \views_calc_fields_form_validate()
- 7 views_calc.module \views_calc_fields_form_validate()
Validate the views calc settings
File
- ./
views_calc.module, line 287 - This module will allow you to add calculated fields to views tables and compute (SUM, COUNT, AVG, etc) columns of numeric data in a views table.
Code
function views_calc_fields_form_validate($form_id, $form_values) {
$edit = $form_values;
foreach ($edit as $delta => $item) {
if ($item['calc'] == '' || !is_numeric($delta)) {
// remove blank fields, don't save them
unset($form_values[$delta]);
}
else {
// Remove all valid values from calc, if anything is left over, it is invalid.
// First, remove all field names.
$repl = array();
$patterns = array();
foreach (_views_calc_substitutions() as $key => $value) {
$key = trim($value);
$count = strlen($value);
$replace = preg_quote($value);
$patterns[] = "`(^|[^\\\\\\\\])" . $replace . "`";
$repl[] = '${1}';
}
$remaining = trim(preg_replace($patterns, $repl, $item['calc']));
// Next, remove functions and numbers.
$repl = array();
$patterns = array();
foreach (_views_calc_replacements() as $value) {
$patterns[] = "`(^|[^\\\\\\\\])" . preg_quote(trim($value)) . "`";
$repl[] = '${1}';
}
$remaining = trim(preg_replace($patterns, $repl, $remaining));
if (!empty($remaining)) {
form_set_error($form_values[$delta]['calc'], t('The values %remaining in %field are not allowed.', array(
'%remaining' => $remaining,
'%field' => $item['label'],
)));
}
}
}
}