表单模板不起作用(yii2)

时间:2015-11-01 08:37:35

标签: php html yii2

我设置了参数形式:



<form id="w0" class="form-horizontal" action="/web/index.php?r=site%2Freg" method="post">
    <input type="hidden" name="_csrf" value="cjZfVVZNOElDbml4NBlhMBRbcjslfFIvFg4OJm4aFSpERDI5Zn19OA==">
    <div class="control-group">
        <b>Регистрация</b>
    </div>
    <div class="form-group field-user-login required">
        <input type="text" id="user-login" class="asd" name="User[login]" placeHolder="Логин">
        <div class="help-block"></div>
    </div>
    <div class="form-group field-user-password required">
        <input type="text" id="user-password" class="asd" name="User[password]" placeHolder="Пароль">
        <div class="help-block"></div>
    </div>
    <div class="form-group field-user-repassword required">
        <input type="text" id="user-repassword" class="asd" name="User[repassword]" placeHolder="Повторите пароль">
        <div class="help-block"></div>
    </div>

</form>
&#13;
&#13;
&#13;

结果,它仍然使用标准类变成标准形式:

&#13;
&#13;
Storage.getObjectInfo
&#13;
&#13;
&#13;

我不需要这些课程和div,并且需要&#34; help-block&#34;类。

1 个答案:

答案 0 :(得分:1)

做类似的事情:

$form->field($model, 'username', [ 'inputTemplate' => '<div class="input-group input-group-sm"><span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>{input}</div>'])->label(false)->textInput(['placeholder'=>'Your Email']);

更新了为所有人定制模板:

$form = ActiveForm::begin([
'layout' => 'horizontal',
'fieldConfig' => [
    'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
    'horizontalCssClasses' => [
        'label' => 'col-sm-4',
        'offset' => 'col-sm-offset-4',
        'wrapper' => 'col-sm-8',
        'error' => '',
        'hint' => '',
    ],
  ],
 ]);

参考:bootstrap activeform yii2 doc和{{3}}