You are here

function customfilter_filter_edit_validate in Custom filter 7

Same name and namespace in other branches
  1. 6 customfilter.admin.inc \customfilter_filter_edit_validate()
  2. 7.2 customfilter.module \customfilter_filter_edit_validate()

Validate callback for the filter edit form.

See also

customfilter_filter_edit()

File

./customfilter.module, line 872
Allows the users with the right permission to define custom filters.

Code

function customfilter_filter_edit_validate($form, &$form_state) {
  if (!empty($form_state['values']['type'])) {
    $type = trim($form_state['values']['type']);
    if (!preg_match('!^[a-z0-9_]+$!', $type)) {
      form_set_error('type', t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
    }
    elseif (db_query("SELECT count(*) FROM {customfilter_filter} WHERE type = :type AND fid <> :fid", array(
      ':type' => $type,
      ':fid' => $form_state['values']['fid'],
    ))
      ->fetchField()) {
      form_set_error('type', t('The machine-readable name must be unique.'));
    }
  }
}