You are here

function lockr_admin_advanced_validate in Lockr 7.2

Same name and namespace in other branches
  1. 7 include/advanced_form.inc \lockr_admin_advanced_validate()

Validate advanced settings.

1 string reference to 'lockr_admin_advanced_validate'
lockr_admin_advanced_form in include/advanced_form.inc
Returns form array for advanced settings.

File

include/advanced_form.inc, line 59
Form handlers for advanced admin settings.

Code

function lockr_admin_advanced_validate($form, &$form_state) {
  $values = $form_state['values'];
  if (!$values['custom']) {
    return;
  }
  $cert_path = $values['custom_cert'];
  if (!$cert_path) {
    form_set_error('custom_cert', t('Certificate location is required for custom certs'));
    return;
  }
  if (substr($cert_path, 0, 10) === 'private://') {
    $private_wrapper = new DrupalPrivateStreamWrapper();
    $private_wrapper
      ->setUri($cert_path);
    $cert_path = $private_wrapper
      ->realpath();
  }
  elseif ($cert_path[0] !== '/') {
    $cert_path = DRUPAL_ROOT . "/{$cert_path}";
  }
  if (is_dir($cert_path) || !is_readable($cert_path)) {
    form_set_error('custom_cert', t('Certificate must be a readable file'));
  }
}