Skip to main content
Commonmark migration
Source Link

If your form element is defined like that:

$form['panes']['webform_nid31'][0]['contact_person'] = array( ... );

your form_set_error call should look like that:

form_set_error('panes][webform_nid31][0][contact_person',
                t('You must select a name for this group of settings.'));

You need to set full path to element, without outside [ and ]. You could have many "contact_person" fields in one form, just in different branches of a form tree. Using only last index would made setting errors ambiguous, thus it's not supported. At least officially. Might work, but only as an undocumented feature.

Formatting this string is described in API:

Parameters

 

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

Copied from form_set_error() field not highlited red

If your form element is defined like that:

$form['panes']['webform_nid31'][0]['contact_person'] = array( ... );

your form_set_error call should look like that:

form_set_error('panes][webform_nid31][0][contact_person',
                t('You must select a name for this group of settings.'));

You need to set full path to element, without outside [ and ]. You could have many "contact_person" fields in one form, just in different branches of a form tree. Using only last index would made setting errors ambiguous, thus it's not supported. At least officially. Might work, but only as an undocumented feature.

Formatting this string is described in API:

Parameters

 

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

Copied from form_set_error() field not highlited red

If your form element is defined like that:

$form['panes']['webform_nid31'][0]['contact_person'] = array( ... );

your form_set_error call should look like that:

form_set_error('panes][webform_nid31][0][contact_person',
                t('You must select a name for this group of settings.'));

You need to set full path to element, without outside [ and ]. You could have many "contact_person" fields in one form, just in different branches of a form tree. Using only last index would made setting errors ambiguous, thus it's not supported. At least officially. Might work, but only as an undocumented feature.

Formatting this string is described in API:

Parameters

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

Copied from form_set_error() field not highlited red

Source Link
colan
  • 2.2k
  • 1
  • 24
  • 36

If your form element is defined like that:

$form['panes']['webform_nid31'][0]['contact_person'] = array( ... );

your form_set_error call should look like that:

form_set_error('panes][webform_nid31][0][contact_person',
                t('You must select a name for this group of settings.'));

You need to set full path to element, without outside [ and ]. You could have many "contact_person" fields in one form, just in different branches of a form tree. Using only last index would made setting errors ambiguous, thus it's not supported. At least officially. Might work, but only as an undocumented feature.

Formatting this string is described in API:

Parameters

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

Copied from form_set_error() field not highlited red