表单模板不起作用(yii2)

时间:2022-10-05 09:49:11

I set the form parametres:

我设置表格参数:

<? $form = ActiveForm::begin(
    [
        'options' => ['class' => 'form-horizontal'],
        'fieldConfig' => 
        [
            'template' => '<div class="control-group">{input}</div>.<div class="control-group error">{error}</div>',
        ],
    ]); 
?>

<div class="control-group">
    <b>Регистрация</b>
        </div>
<?
    echo $form->field($model, 'login', ['template' => "{input}{error}", 'inputOptions' => array('placeHolder' => 'Логин')]);
    echo $form->field($model, 'password', ['template' => "{input}{error}", 'inputOptions' => array('placeHolder' => 'Пароль')]);
    echo $form->field($model, 'repassword', ['template' => "{input}{error}", 'inputOptions' => array('placeHolder' => 'Повторите пароль')]);
?>

As a result, it still turns a standard form with standart classes:

因此,它仍然使用标准类转换为标准形式:

<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>

I don't need this classes and div with "help-block" class.

我不需要这个类和div与“help-block”类。

1 个解决方案

#1


1  

do something like :

做类似的事情:

$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']);

Updatedcustomize template for all :

为所有人更新了自定义模板:

$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' => '',
    ],
  ],
 ]);

references : yii2 doc and bootstrap activeform yii2 doc

参考:yii2 doc和bootstrap activeform yii2 doc

#1


1  

do something like :

做类似的事情:

$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']);

Updatedcustomize template for all :

为所有人更新了自定义模板:

$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' => '',
    ],
  ],
 ]);

references : yii2 doc and bootstrap activeform yii2 doc

参考:yii2 doc和bootstrap activeform yii2 doc