Closed (won't fix)
Project:
Drupal core
Version:
5.10
Component:
forms system
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Oct 2008 at 11:02 UTC
Updated:
20 Sep 2009 at 09:06 UTC
Currently Form API only displayed error messages at the top of the page with each field that has an error would be highlighted in red. Most of the form library has this feature so it would be pity FAPI doesn't has it. For now I plan to just hack up _form_set_class() function since this is the one that is called by all the element prior to rendering.
function _form_set_class(&$element, $class = array()) {
if ($element['#required']) {
$class[] = 'required';
}
if (form_get_error($element)){
$class[] = 'error';
$element['#title'] = '<span style="color: red;">'.form_get_error($element).'</span><br />'.$element['#title'];
}
if (isset($element['#attributes']['class'])) {
$class[] = $element['#attributes']['class'];
}
$element['#attributes']['class'] = implode(' ', $class);
}
I used #title since there's no other property that can output some content before the element.
Comments
Comment #1
walker2238 commentedIs there not a way to override this function? I'm kinda looking for something along the same lines as you. I have yet to find a way to override this and don't really like the idea of making a hack in the core files. The way drupal outputs status and error messages is driving me nuts. As you suggested putting the messages beside each field is a much more user friendly way.
Comment #2
k4ml commentedTurn out that we can override this in theme function though not really clean but I think much better. Found this at http://www.imedstudios.com/labs/node/4 and here is my version which display the error on top of the element instead of bottom:-
Comment #3
dwwThis isn't going to be fixed in D5 (or D6) for that matter. Looks like something like this might land in D7 over at #447816: WCAG violation: Relying on a color by itself to indicate a field validation error.