Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 ActiveForm field add html code

Tags:

php

field

yii2

I have this code in Yii2:

<?= $form->field($model, 'username',$opzioni)->textInput(array('placeholder' => 'Username'));  ?>

generate this:

<div class="input-icon field-loginform-username required">
    <label class="control-label" for="loginform-username">Username</label>
    <input id="loginform-username" class="form-control" type="text" placeholder="Username" name="LoginForm[username]">
    <div class="help-block"></div>
</div>

and i want to do this

<div class="input-icon field-loginform-username required">
    <label class="control-label" for="loginform-username">Username</label>
    **<i class="fa fa-user"></i>**
    <input id="loginform-username" class="form-control" type="text" placeholder="Username" name="LoginForm[username]">
    <div class="help-block"></div>
</div>

It's possible with the original source?

like image 619
user3575904 Avatar asked Apr 26 '14 13:04

user3575904


1 Answers

refering to http://stuff.cebe.cc/yii2docs/yii-widgets-activefield.html#$template-detail

template = "{label}\n{input}\n{hint}\n{error}"

your code should be like this:

<?= $form->field($model, 'username', [
  'template' => "{label}\n<i class='fa fa-user'></i>\n{input}\n{hint}\n{error}"
])->textInput(array('placeholder' => 'Username'));  ?>
like image 168
user1852788 Avatar answered Nov 03 '22 23:11

user1852788