11

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?

1
  • 4
    Don't forget to accept the users' answer if it is correct. This site runs on goodwill and reputation :) Commented May 27, 2014 at 6:16

1 Answer 1

41

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'));  ?>
Sign up to request clarification or add additional context in comments.

1 Comment

<?= $form->field($model, 'username', ['template' => "{label}\n<i class='fa fa-user'></i>\n{input}\n{hint}\n{error}"])->textInput(array('placeholder' => 'Username')); ?> thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.