You are here

function _filefield_widget_validate in FileField 5.2

Validate the form widget.

2 calls to _filefield_widget_validate()
filefield_js in ./filefield.module
Menu callback for JavaScript-based uploads.
filefield_widget in ./filefield.module
Implementation of hook_widget().

File

./filefield.module, line 685
Defines a file field type.

Code

function _filefield_widget_validate($node, $field, $items) {
  if (!$field['required']) {
    return;
  }

  // if there aren't any items.. throw an error.
  if (!count($items)) {
    form_set_error($field['field_name'], t('@field is required. Please upload a file.', array(
      '@field' => $field['widget']['label'],
    )));
  }
  else {

    // Sum all the items marked for deletion, so we can make sure the end user
    // isn't deleting all of the files.
    $count_deleted = 0;
    foreach ($items as $item) {
      $count_deleted += isset($item['delete']) && $item['delete'];
    }
    if (count($items) == $count_deleted) {
      form_set_error($field['field_name'], t('@field is required. Please keep at least one file or upload a new one.', array(
        '@field' => $field['widget']['label'],
      )));
    }
  }
}