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
Comment #1
pedrofaria commentedNicolas,
you're completely right.
Thanks for your fix and for your PS :)
I will commit your fix soon.
Regards,
Pedro Faria
Comment #2
pedrofaria commentedCommited!
Please, review it and report here!
Thanks again!
Comment #3
pedrofaria commentedComment #4
pedrofaria commented