You are here

function forena_machine_name_validate in Forena Reports 8

Same name and namespace in other branches
  1. 7.5 forena.module \forena_machine_name_validate()
  2. 7.4 forena.module \forena_machine_name_validate()

Custom override of machine_name validate that does not include

Parameters

unknown $element:

unknown $form_state:

1 string reference to 'forena_machine_name_validate'
forena_element_info in ./forena.module
Create a derivative to the machine name field with relaxed restrictions.

File

./forena.module, line 764

Code

function forena_machine_name_validate($element, &$form_state) {

  // Verify that the machine name not only consists of replacement tokens.
  if (preg_match('@^' . $element['#machine_name']['replace'] . '+$@', $element['#value'])) {
    form_error($element, t('The machine-readable name must contain unique characters.'));
  }

  // Verify that the machine name contains no disallowed characters.
  if (preg_match('@' . $element['#machine_name']['replace_pattern'] . '@', $element['#value'])) {
    if (!isset($element['#machine_name']['error'])) {

      // Since a hyphen is the most common alternative replacement character,
      // a corresponding validation error message is supported here.
      if ($element['#machine_name']['replace'] == '-') {
        form_error($element, t('The machine-readable name must contain only letters, numbers, and hyphens.'));
      }
      else {
        form_error($element, t('The machine-readable name must contain only letters, numbers, and underscores.'));
      }
    }
    else {
      form_error($element, $element['#machine_name']['error']);
    }
  }
}