You are here

function imce_fileop_form_validate in IMCE 7

Same name and namespace in other branches
  1. 6.2 inc/imce.page.inc \imce_fileop_form_validate()
  2. 6 inc/page.inc \imce_fileop_form_validate()

Validate file operations form.

File

inc/imce.page.inc, line 297
Implements the file browser.

Code

function imce_fileop_form_validate($form, &$form_state) {
  $imce =& $form_state['build_info']['args'][0]['imce'];

  // Check if the filenames is empty.
  if ($form_state['values']['filenames'] == '') {
    return form_error($form['filenames'], t('Please select a file.'));
  }

  // Filenames come separated by colon.
  $filenames = explode(':', $form_state['values']['filenames']);
  $cnt = count($filenames);

  // Check the number of files.
  if ($imce['filenum'] && $cnt > $imce['filenum']) {
    return form_error($form['filenames'], t('You are not allowed to operate on more than %num files.', array(
      '%num' => $imce['filenum'],
    )));
  }

  // Check if there is any illegal choice.
  for ($i = 0; $i < $cnt; $i++) {
    $filenames[$i] = $filename = rawurldecode($filenames[$i]);
    if (!isset($imce['files'][$filename])) {
      watchdog('imce', 'Illegal choice %choice in !name element.', array(
        '%choice' => $filename,
        '!name' => t('directory (%dir)', array(
          '%dir' => imce_dir_uri($imce),
        )),
      ), WATCHDOG_ERROR);
      return form_error($form['filenames'], t('An illegal choice has been detected. Please contact the site administrator.'));
    }
  }
  $form_state['values']['filenames'] = $filenames;
}