首页 > 代码库 > Yii 2.0 ActiveForm生成表单 ,控制表单label和filed样式,filed一旦报错,前面lable颜色跟着变,看图,帮你解决
Yii 2.0 ActiveForm生成表单 ,控制表单label和filed样式,filed一旦报错,前面lable颜色跟着变,看图,帮你解决
需要生成如下图的表单样式,图一:
正确代码:
<?php $form = ActiveForm::begin([
‘id‘ => ‘login-form‘,
‘options‘ => [‘class‘ => ‘form-horizontal‘],
‘fieldConfig‘ => [
‘template‘ => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
‘labelOptions‘ => [‘class‘ => ‘col-lg-1‘],
],
]); ?>
<?= $form->field($user, ‘mobile‘) ?>
<?=$form->field($user,‘pass‘)->passwordInput();?>
<?=$form->field($user,‘configpass‘)->passwordInput();?>
<?=Html::submitButton(‘提交‘,[‘class‘=>‘btn btn-success submit‘]);?>
<?php ActiveForm::end();?>
部分读者会遇到图二的问题
原因在此:
Yii 2.0 ActiveForm生成表单 ,控制表单label和filed样式,filed一旦报错,前面lable颜色跟着变,看图,帮你解决