You are here

function access_scheme_form_validate in Access Control Kit 7

Form validation handler for access_scheme_form().

See also

access_scheme_form()

access_scheme_form_submit()

File

./access_schemes.admin.inc, line 353
Access schemes administrative UI for the access control kit module.

Code

function access_scheme_form_validate($form, &$form_state) {
  $scheme = $form_state['scheme'];

  // Validate the machine name on new schemes.
  if (empty($scheme->sid)) {
    $machine_name = $form_state['values']['machine_name'];

    // Some machine names cannot be used.
    $disallowed = array(
      // 'theme' would conflict with theme_access_scheme_form() if we implement
      // per scheme form IDs (the way the node module does).
      'theme',
      // 'list' and 'add' would conflict with menu callbacks.
      'list',
      'add',
    );

    // We also don't want machine names that evaluate to FALSE.
    if (empty($machine_name) || in_array($machine_name, $disallowed)) {
      form_set_error('machine_name', t('Invalid machine-readable name. Enter a name other than %invalid.', array(
        '%invalid' => $machine_name,
      )));
    }
  }

  // Check for duplicate human-readable names.
  $name = trim($form_state['values']['name']);
  if ((empty($scheme->name) || $scheme->name != $name) && in_array($name, access_scheme_names())) {
    form_set_error('name', t('The name %name is already in use.', array(
      '%name' => $name,
    )));
  }
}