Yii2 model validation message from the label assigned via ActiveForm

Viewed 367

Is there any way to prompt for validation with the attribute's label assigned via ActiveForm?

For instance I have a model attribute amount and the label defined in its attributeLabels function is "Amount"

But while generating form I neeed the label "Fees" so:
$form->field($model, 'amount')->textInput(['maxlength' => true])->label('Fees')

After validation it prompts me "Amount cannot be blank" - it is known to me that we can write a rule to change message but according to my requirements, same attribute (from same model) is having different labels on different forms.

I know that back-end implementation of default message uses:
'message' => '{attribute} cannot be blank.' does anyone know if there is any {x} by which the assigned label in ActiveForm can be retrieved?


PS: I know that this problem can be resolved by scenarios. But it would be hectic to write rule for every field which has dual label.

2 Answers
Related