[drupal] define validation function for list form

This commit is contained in:
Bart Van Der Meerssche 2011-03-18 12:35:05 +00:00
parent e2e9fee434
commit 7a2f7270be
1 changed files with 6 additions and 0 deletions

View File

@ -891,6 +891,7 @@ function _logger_sensors_form() {
'#options' => $rows,
'#multiple' => TRUE,
'#default_value' => $defaults,
'#element_validate' => array('_logger_sensors_list_validate'),
);
$form['sensors']['submit'] = array
@ -904,6 +905,11 @@ function _logger_sensors_form() {
return $form;
}
function _logger_sensors_list_validate($element, &$form_state) {
if (count(array_filter($form_state['values']['list'])) > 5)
form_error($element, t('A maximum of five sensors can be plotted on a single chart.'));
}
function _logger_sensors_submit($form, &$form_state) {
foreach ($form_state['values']['list'] as $sensor => $chart) {
if ($chart)