I'm adding validation errors to fields using addErrors($record->getErrors())
which then read like e.g. "My Field cannot be blank."
But I'm wondering where I can translate the field name, which I think is generated from the ID attribute myField
?
Update:
Template:
<input type="hidden" name="action" value="example/saveExample">
{{ forms.textField({
label: 'My Field'|t,
id: 'myField',
name: 'myField',
value: null,
errors: example is defined ? example.errors('myField'),
}) }}
Service function called from actionSaveExample
:
public function saveExample(ExampleModel $example)
{
$exampleRecord = ExampleRecord::model()->findById($example->id);
$exampleRecord->myField = $example->myField;
if ($exampleRecord->validate())
{
// save
}
else
{
$rule->addErrors($ruleRecord->getErrors());
return false;
}
}