You are here

function environment_indicator_ui_validate in Environment Indicator 7.2

Validation callback for environment_indicator_ui_form().

1 string reference to 'environment_indicator_ui_validate'
environment_indicator_ui.inc in plugins/export_ui/environment_indicator_ui.inc

File

./environment_indicator.module, line 225
Module implementation file.

Code

function environment_indicator_ui_validate($form, &$form_state) {
  $color_elements = array(
    'color',
    'text_color',
  );
  $values = $form_state['values'];
  foreach ($color_elements as $color_element) {

    // Validate that the colors are in valid Hex format.
    if (!preg_match('/^#[a-f0-9]{6}$/i', $values[$color_element])) {
      form_set_error($color_element, t('%name must be a valid color in the format <em>#RRGGBB</em>.', array(
        '%name' => $form[$color_element]['#title'],
      )));
    }
  }

  // Validate hostname regexp.
  $regex = preg_quote($values['regexurl'], '/');
  if (preg_match("/{$regex}/", '') === FALSE) {
    form_set_error('regexurl', t('Hostname must be a valid regular expression.'));
  }
}