[eluser]adamp1[/eluser]
I believe I have found a bug in the Form Validation library, around the use of language strings.
Say we have a form as follows:
Code:
<input type='password' name='password'/>
<input type='password' name='password_again'/>
And say we have the following validation rules
Code:
$this->form_validation->set_rules('password','lang:password','required');
$this->form_validation->set_rules('password_again','lang:password_again', 'matches[password]');
Now what we have here is a simple rule so if the fields don't match an error is thrown. The error is thrown but the wrong field name is used.
Code:
The Password-again field does not match the lang:password field.
The issue is the second field name is not being translated.
The issue can be found in the Form_validation.php library file on line 661.
Code:
if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label']))
{
$param = $this->_field_data[$param]['label'];
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);
From the code above you will see the current row label is translated, but the $param label is not.
Therefore the following is required.
Code:
if (isset($this->_field_data[$param]) AND isset($this->_field_data[$param]['label']))
{
$param = $this->_translate_fieldname($this->_field_data[$param]['label']);
}
// Build the error message
$message = sprintf($line, $this->_translate_fieldname($row['label']), $param);