When validating a form, form.inc's form_error() tags form elements with the #error property. The #error property, however, appears to the most underused property of the form API: it is simply never seen again. Even form_set_error and form_get_error, do not actually use it. And that's a shame for two reasons:
1. It would be nice for the user if the error message were displayed near to the offending element, instead of only at the very top of a form. Especially with a long form, it's not always clear what exactly the problem was with a form element outlined in red without the error message next to it to explain where the user went wrong.
2. It would be handy for the developer to be able to take action on an element with the #error property.

I have found, for instance, that users often unknowingly duplicate nodes: not realizing they have already saved a node, they start a new one, type in one or two letters in the title field and the auto-complete feature of the browser fills in the information they have just entered. They then submit the node and to their confusion end up with two almost identical nodes.
For the developer it's not hard to spot this in a hook_validate function by checking if a node with a similar title already exists, but what is hard is then helping the user take a decision. The #error property has disappeared from the $form array and so hook_form_alter cannot be used to, for instance, provide the user with a link to the original node or perhaps a checkbox to indicate that they don't mind having two nodes with identical titles.

Comments

marcingy’s picture

Version: 5.0 » 8.x-dev

bumping version

arhak’s picture

first point is being covered at #447816: WCAG violation: Relying on a color by itself to indicate a field validation error

for second point there are contributed modules which takes care of disabling the submit button to avoid duplicated posts,
or any other approach seems to be better handled by a contrib mod

marcingy’s picture

Status: Active » Closed (duplicate)

Marking as duplicate for part 1.