You are here

function smiley_overview_form_validate in Smiley 7

Smileys overview form validate.

File

./smiley.admin.inc, line 101
Smileys administrative pages.

Code

function smiley_overview_form_validate($form, &$form_state) {
  $values = $form_state['values'];
  foreach ($values as $sid => $value) {
    if (is_array($value) && !empty($value['uri']) && empty($value['delete'])) {
      $exist = db_query('SELECT COUNT(*) FROM {smiley} WHERE uri = :url AND sid <> :sid', array(
        ':url' => $value['uri'],
        ':sid' => is_numeric($sid) ? $sid : -1,
      ))
        ->fetchColumn();
      if ($exist) {
        form_set_error($sid . '][uri', t('This uri already exists'));
      }
      elseif (!preg_match('#^[a-z0-9_\\-/]*\\.(gif|png|jpg)$#i', $value['uri'])) {
        form_set_error($sid . '][uri', t('Incorrect uri.'));
      }
    }
  }
}