I have multiple instances of the same field widget attached to different entity forms on the same page. On validating one of these forms, when I set form_set_error($field_name, '...'), every one of these widgets get highlighted. Is there a way to get around this somehow?

1 Answer 1


Check out the API page for form_set_error. This bit should help you out:

$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'.

In your case you'll just want to make sure that the parent item is different for each instance of that field, then set the error with form_set_error($parent_name . '][' . $field_name, '...')

  • Forgot to add this in the question itself but I don't want to change #parents as that would change the way I access the value of the field(s) in different parts of the code. I just want to uniquely replace the name of the fields on the client-side so that the validator can use that just to flag the correct element. Do you think this can be done? Commented Aug 24, 2011 at 3:51

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.