function customfilter_filter_add_validate in Custom filter 7
Same name and namespace in other branches
- 6 customfilter.admin.inc \customfilter_filter_add_validate()
- 7.2 customfilter.module \customfilter_filter_add_validate()
Validate callback for the add filter form.
See also
File
- ./
customfilter.module, line 760 - Allows the users with the right permission to define custom filters.
Code
function customfilter_filter_add_validate($form, &$form_state) {
if (!empty($form_state['values']['type'])) {
$type[] = trim($form_state['values']['type']);
if (!preg_match('!^[a-z0-9_]+$!', $type[0])) {
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'", array(
':type' => $type,
))
->fetchField()) {
form_set_error('type', t('The machine-readable name must be unique.'));
}
}
}