这是我添加带有文本字段的图标的方式。还添加了生成输出的图像。 我不想使用Krajee Yii Extensions。所以我开始阅读文档。
$form = \yii\widgets\ActiveForm::begin([
'id' => 'form-id',
'options' => ['class' => 'form-horizontal'],
'enableClientValidation'=> false,
'enableAjaxValidation'=> true,
'validateOnSubmit' => true,
'validateOnChange' => true,
'validateOnType' => true,
'action' => 'youraction',
'validationUrl' => 'yourvalidation'
]);
echo $form->field($model, 'fieldname')->begin();
echo Html::activeLabel($model,'fieldname', ["class"=>"col-sm-3 control-label"]); ?>
<div class="input-group col-sm-4 ">
<span class="input-group-addon">
<span class="glyphicon glyphicon-subtitles"></span>
</span>
<?php echo Html::activeTextInput($model, 'fieldname', [
'class'=>'form-control',
'autocomplete'=>'off'
]
); ?>
</div>
<?php echo Html::error($model,'origin', ['class' => 'help-block']);
echo $form->field($model, 'origin')->end();
\yii\widgets\ActiveForm::end();
答案 0 :(得分:8)
这是一个问题,或者您正在告诉我们您是如何做到的?
您还应该能够执行以下操作:
<?= $form->field($model, 'fieldname', ['template' => '
<div class="col-sm-2">{label}</div>\n
<div class="col-sm-10">
<div class="input-group col-sm-4 ">
<span class="input-group-addon">
<span class="glyphicon glyphicon-subtitles"></span>
</span>
{input}
</div>
{error}{hint}
</div>'])->textInput(['data-default' => '']) ?>