You are here

function fivestar_color_form_validate in Fivestar 5

Same name and namespace in other branches
  1. 6.2 includes/fivestar.color.inc \fivestar_color_form_validate()
  2. 6 fivestar_color.inc \fivestar_color_form_validate()

Validate handler for color form.

File

./fivestar_color.inc, line 157
File containing functions relating to the color widget.

Code

function fivestar_color_form_validate($form_id, &$form_values) {
  if ($form_values['fivestar_color_type'] == 'default' || $form_values['fivestar_color_type'] == '') {
    form_set_value(array(
      '#parents' => array(
        'fivestar_color_type',
      ),
    ), 'default');
    return;
  }
  foreach ($form_values['fivestar_colors'] as $key => $value) {
    $form_values['fivestar_colors'][$key] = trim(drupal_strtolower($value));
    if (!preg_match('/^#([0-9a-f]{3}|[0-9a-f]{6})$/', $form_values['fivestar_colors'][$key]) && !($key == 'matte' && ($value == 'none' || $value == ''))) {
      form_set_error('fivestar_colors][' . $key, t('The entered value %color is not a valid hex color.', array(
        '%color' => $value,
      )));
    }
  }
}