You are here

function _element_validate_options_size in Name Field 6

Helper form element validator.

1 call to _element_validate_options_size()
name_field_settings in ./name.module
Implementation of hook_field_settings().

File

./name.module, line 1101
Defines an API for displaying and inputing names.

Code

function _element_validate_options_size($field_options, $max_length, $label) {
  $values = array_filter(explode("\n", $field_options));
  $long_options = array();
  $options = array();
  foreach ($values as $value) {
    $value = trim($value);

    // Blank option - anything goes!
    if (strpos($value, '--') === 0) {
      $options[] = $value;
    }
    elseif (drupal_strlen($value) > $max_length) {
      $long_options[] = $value;
    }
    elseif (!empty($value)) {
      $options[] = $value;
    }
  }
  if (count($long_options)) {
    form_set_error('field_settings][title_options', t('The following options exceed the maximun allowed %label length: %options', array(
      '%options' => implode(', ', $long_options),
      '%label' => $label,
    )));
  }
  elseif (empty($options)) {
    form_set_error('field_settings][title_options', t('%label are required.', array(
      '%label' => $label,
    )));
  }
}