Reputation: 161
I need to add image into form field in yii2. I can't find an example for how can I do that.I need to do something like that:
I know how to add placeholder and do that, but dont know how to add the image.
<?= $form->field($model, 'email')->textInput()->input('email',['placeholder' => "E-mail"])->label(false); ?>
Upvotes: 0
Views: 1159
Reputation: 1024
I think the Easiest way to do it will be with CSS.
<div class="input_container">
<span class="input_placeholder_icon"><i class="fa fa-envelope-o" aria-hidden="true"></i></span>
<?= $form->field($model, 'email')->textInput()->input('email',['placeholder' => "E-mail"])->label(false); ?>
</div>
And in your CSS:
.input_container{
position: relative;
}
.input_placeholder_icon{
position: absolute;
top: 2px;
color: red;
left: 2px;
font-size: 21px;
width: 50px;
}
You can change some settings in CSS depending on your need. I have used font-awesome icon in the example.
Upvotes: 0