function styleswitcher_style_form_validate in Style Switcher 6.2
Same name and namespace in other branches
- 7.2 styleswitcher.admin.inc \styleswitcher_style_form_validate()
Form validation handler for styleswitcher_style_form().
See also
styleswitcher_style_form_submit()
File
- ./
styleswitcher.admin.inc, line 243 - Styleswitcher configuration functionality.
Code
function styleswitcher_style_form_validate($form, &$form_state) {
// Trim text values now, so submission handlers get them fully validated.
// No need to trim name, because it's validated by a machine-name pattern.
form_set_value($form['label'], trim($form_state['values']['label']), $form_state);
$name = $form_state['values']['name'];
$old_name = $form_state['values']['old_name'];
// Verify that the machine name not only consists of replacement tokens.
if (preg_match('@^_+$@', $name)) {
form_error($form['name'], t('The machine-readable name must contain unique characters.'));
}
// Verify that the machine name contains no disallowed characters.
if (preg_match('@[^a-z0-9_]+@', $name)) {
form_error($form['name'], t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
}
// Verify that the machine name is unique.
if ('custom/' . $name !== $old_name && styleswitcher_style_load('custom/' . $name, '')) {
form_error($form['name'], t('The machine-readable name is already in use. It must be unique.'));
}
$path = $form_state['values']['path'];
if ($path === '') {
// Set the path back to NULL.
form_set_value($form['path'], NULL, $form_state);
}
else {
$path = trim($path);
form_set_value($form['path'], $path, $form_state);
if (!is_file($path) && !menu_path_is_external($path)) {
form_set_error('path', t('Stylesheet file %path does not exist.', array(
'%path' => $path,
)));
}
}
}