You are here

function encrypt_admin_settings_validate in Encrypt 6

Same name and namespace in other branches
  1. 7 includes/encrypt.admin.inc \encrypt_admin_settings_validate()

Validate form function for encrypt_admin_settings(). Checks if users really wants to change path, and whether key can be written.

File

includes/encrypt.admin.inc, line 79
This file holds the functions for the encrypt Admin settings.

Code

function encrypt_admin_settings_validate($form, &$form_state) {

  // Run requirements (include install file first)
  module_load_install('encrypt');
  $requirements = encrypt_requirements('runtime');

  // Check if passes requirements and checkbox is not checked and path is different
  if ($requirements['encrypt_keys']['severity'] == REQUIREMENT_OK && $form_state['values']['encrypt_update_key'] != TRUE && $form_state['values']['encrypt_secure_key_path'] != variable_get('encrypt_secure_key_path', '')) {
    form_set_error('encrypt_update_key', t('If you change the key after the data has been encrypted with it, you will not be able to retrieve that data.  You can copy your key to a new directory and set the new directory.  If you really want to change the path, please check the Change Key Path checkbox.'));
  }

  // Check if path selected is writable if one is inputted
  if (!empty($form_state['values']['encrypt_secure_key_path'])) {
    if (!file_check_directory($form_state['values']['encrypt_secure_key_path'], 0, 'encrypt_secure_key_path')) {
      form_set_error('encrypt_secure_key_path', t('Directory does not exist or is not writable.'));
    }
  }
}