i have a $form that defines $form['date'] as #tree => true, and i have subsequent form text fields for $form['date']['start_date'] and $form['date']['end_date'].

i am able to do validation and form_set_error('date', 'msg'), which outlines BOTH start_date and end_date text fields with a red error box. however, how do i outline ONLY start_date or end_date? i've tried form_set_error('start_date', 'msg') but to no avail :/

i want the functionality to either outline BOTH in a single error check (eg, is end_date > start_date) or just outline one of them (eg, is start_date is an invalid date)

thanks

Comments

AjK’s picture

Try....

  form_set_error('date][start_date', 'msg');
  form_set_error('date][end_date', 'msg');

I believe it's documented here: http://api.drupal.org/api/HEAD/function/form_set_error

:)

wongle’s picture

this is great, it works! i mustve completely missed that, since i had been reading that page too :P

thanks :)

ravimane23’s picture

Hi,

I am also looking for same kind of solution. I also have created a form $form[#tree] = TRUE.
But in above example its only for two dimensional array.

In my form the array generated is three dimensional, so I got stuck over there.

But after referring form_set_error URL http://api.drupal.org/api/HEAD/function/form_set_error

This example was there for Druapl 6. When I tried it in my custom form in Drupal 7 and its working. :)

Thanks Ajk for giving this solution.