Yii2 labelEx of ActiveForm
2 answers
The method is Yii2as follows:
<?= $form->field($model, 'fieldName')->label('Label Of FieldName'); ?>
So yours will look something like this:
<?= $form->field($model, 'text')->label('Text'. Html::tag('span', '*',['class'=>'required'])); ?>
Please note that you need to add use yii\helpers\Html;to your view. Otherwise, you need to replace Html::with yii\helpers\Html::.
Update
For those who suffer from requiredthe css class, it is automatically added to DIVthe form field parent element :
You can remove it as shown below:
$form = ActiveForm::begin(['requiredCssClass' => '' ...
, . , css. .
+7