You are here

function private_files_download_permission_get_directory_form_validate in Private files download permission 7.2

(Form callback.) Validates the directory form.

File

./private_files_download_permission.module, line 334
Handles both module settings and its behaviour.

Code

function private_files_download_permission_get_directory_form_validate($form, &$form_state) {

  // Retrieve $path (which, being required, is surely not blank).
  $path = $form_state['values']['path'];

  // Perform slash validation:
  if (0 < drupal_strlen($path)) {
    $first_character = drupal_substr($path, 0, 1);
    $last_character = drupal_substr($path, -1, 1);

    // ...there must be a leading slash.
    if ('/' !== $first_character && '\\' !== $first_character) {
      form_set_error('path', t('You must add a leading slash.'));
    }
    if (1 < drupal_strlen($path)) {

      // ...there cannot be multiple consecutive slashes.
      if (FALSE !== strpos($path, '//') || FALSE !== strpos($path, '\\\\')) {
        form_set_error('path', t('You cannot use multiple consecutive slashes.'));
      }

      // ...there cannot be trailing slashes.
      if ('/' === $last_character || '\\' === $last_character) {
        form_set_error('path', t('You cannot use trailing slashes.'));
      }
    }
  }
}