Hi,
In my form I have something like:

  $form['AAAA'] = array(
    '#type' => 'fieldset',
    '#title' => t('________'),
    '#tree' => TRUE,
  );
  
  $form['AAAA']['BBBB'] = array(
    '#type' => 'textfield',
    '#title' => t('_______'),
    '#size' => 30,
    '#maxlength' => 30,
  );

When I'm trying to highlight a particular field in fieldset (when validating), it doesn't work:

   form_set_error('BBBB','________');

(I mean it prints the message, but doesn't highlight the field BBBB in red), although this works fine:

   form_set_error('AAAA','________');

Could anyone tell me what am I doing wrong, please?...
Thanks,
Sara

Comments

DGvNp0niToyRspXaaqx3PiQBMn66QXyAq5yrNHpz’s picture

Hello:

If you are trying to highlight a field that is nested in a fieldset (like you are doing above) the documentation here (http://api.drupal.org/api/function/form_set_error/6) instructs under the parameters heading

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

So using that information (and I use this code on a clients website so I know for sure it works) our code should look like this:

form_set_error('AAAA][BBBB', t('Please enter a valid BBBB field below, the value you entered is not allowed'));

Make special note of the form_set_error name used again it is AAAA][BBBB for the nested element.

I hope that helps.

Joshua Powell
www.developedsimple.com

sourabh.iitm’s picture

Works. Thank u.