I have written some custom validation for each element in a form. I use the following method to display errors. It automatically highlights the required fields.

form_set_error('field_athletes_male', 'Athletes Male field is required.'); 

My problem is that there are nested element names like this:


The validation message is shown successfully but the element is not highlighted.

  • From api.drupal.org/api/drupal/includes%21form.inc/function/… "$name: The name of the form element. If the #parents property of your form element is array('foo', 'bar', 'baz') then you may set an error on 'foo' or 'foo][bar][baz'. Setting an error on 'foo' sets an error for every element where the #parents array starts with 'foo'." Commented Mar 25, 2015 at 10:56

1 Answer 1


Its working now, code as follows

form_set_error('field_coaching_programme][und][0][field_organisation_delivered_by', 'Organisation delivered by field is required.');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.