function filefield_node_form_validate in FileField 6.3
Additional #validate handler for the node form.
This function checks the #required properties on file fields and calculates node upload totals for all file fields. The #required property is not properly supported on file fields by Drupal core, so we do this manually.
1 string reference to 'filefield_node_form_validate'
- filefield_widget in ./
filefield.module - Implementation of hook_widget().
File
- ./
filefield_widget.inc, line 560 - This file contains CCK widget related functionality.
Code
function filefield_node_form_validate($form, &$form_state) {
foreach ($form['#field_info'] as $field_name => $field) {
if (!in_array($field['module'], array(
'imagefield',
'filefield',
))) {
continue;
}
$empty = $field['module'] . '_content_is_empty';
$valid = FALSE;
$total_filesize = 0;
if (!empty($form_state['values'][$field_name])) {
foreach ($form_state['values'][$field_name] as $delta => $item) {
if ($empty($item, $field)) {
continue;
}
$valid = TRUE;
$total_filesize += (int) $item['filesize'];
}
}
if (!$valid && $field['required'] && filefield_edit_access($field['type_name'], $field_name, $form['#node'])) {
form_set_error($field_name, t('%title field is required.', array(
'%title' => t($field['widget']['label']),
)));
}
$max_filesize = parse_size($field['widget']['max_filesize_per_node']);
if ($max_filesize && $total_filesize > $max_filesize) {
form_set_error($field_name, t('Total filesize for %title, %tsize, exceeds field settings of %msize.', array(
'%title' => t($field['widget']['label']),
'%tsize' => format_size($total_filesize),
'%msize' => format_size($max_filesize),
)));
}
}
}