1

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:

 field_coaching_programme[und][0][field_organisation_delivered_by][und][0][value]

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

1
  • 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'." Mar 25 '15 at 10:56
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, privacy policy and cookie policy

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