When using a rule on a field that is inside a fieldset, the module will fail to highlight the field due to the label used for the form_set_error function call.

Example form items

$form['spend'] = array(
		'#type' => 'fieldset',
		'#title' => 'How much are you looking to spend ?',
		'#tree' => true
	);
	$form['spend']['min'] = array(
		'#type' => 'textfield',
		'#title' => 'Minimum',
		'#field_prefix' => '$',
		'#required' => true,
		'#size' => 10,
		'#filters' => array('trim'),
		'#rules' => array(
						array('rule' => 'numeric', 'error'=>'Please use only numbers for minimum willing to spend. %field')
					)
	
	);	

When that rule is executed, and is found to have been broken. An error is set using the following
form_set_error($element['#name'] , t($error, array('%field'=>$element['#title'])));
In the case of a fieldset, the element name is parent[child], but for form_set_error it should be parent][child

The fix:
form_set_error( implode("][",$element['#parents']) , t($error, array('%field'=>$element['#title'])));

Ps. Love the module.

Comments

pedrofaria’s picture

Nicolas,

you're completely right.

Thanks for your fix and for your PS :)

I will commit your fix soon.

Regards,

Pedro Faria

pedrofaria’s picture

Status: Active » Needs review

Commited!

Please, review it and report here!

Thanks again!

pedrofaria’s picture

Assigned: Unassigned » pedrofaria
pedrofaria’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.