YII 2 activeformスタイル修正

5316 ワード

<?php $form = ActiveForm::begin([

        'options'=>['enctype'=>'multipart/form-data','class' => 'form-horizontal'],

        'fieldConfig' => [  //         

            'template' => "{label}
<div class=\"col-lg-5\">{input}</div>
<div class=\"col-lg-3\">{error}</div>",
        // {label}
{input}
{hint}
{error}
html
'labelOptions' => ['class' => 'col-lg-2 control-label'], // label ], ]);
?>

 
//        
<?
= $form->field($model, 'img_path',[ 'template' => "{label}
<div class=\"col-lg-3\">{input}</div>
<div class=\"col-lg-2\"><label for=\"uploadImg\" class=\"btn btn-default forfocus1\" onclick=\"changeImg(1,'forfocus');\"> <img src=\"\"></label></div>
{error}", 'labelOptions' => ['class' => 'col-lg-2 control-label'], ])->textInput(['maxlength' => 255,'placeholder'=>' ','readonly'=>true])->label(' ')->hint(' ')
?>

 
以下は完全な例です.
<?php $form = ActiveForm::begin([

        'options'=>['enctype'=>'multipart/form-data','class' => 'form-horizontal'],

        'fieldConfig' => [  

            'template' => "{label}
<div class=\"col-lg-5\">{input}</div>
<div class=\"col-lg-5\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-2 control-label'], ], ]);
?> <?= $form->field($model, 'title')->textInput(['maxlength' => 255,'placeholder'=>' '])->label(' ') ?> <?= $form->field($model, 'img_path',[ 'template' => "{label}
<div class=\"col-lg-3\">{input}</div>
<div class=\"col-lg-2\"><label for=\"uploadImg\" class=\"btn btn-default forfocus1\" onclick=\"changeImg(1,'forfocus');\"> <img src=\"\"></label></div>
{error}", 'labelOptions' => ['class' => 'col-lg-2 control-label'], ])->textInput(['id'=>'img_path','maxlength' => 255,'placeholder'=>' ','readonly'=>true])->label(' ')
?> <?= $form->field($model, 'showImg',[ 'template' => "{label}
<div id=\"showImg\" class='col-lg-10'></div>", 'labelOptions' => ['class' => 'col-lg-2 control-label'], ])->label(' ')
?> <?= $form->field($model, 'link_to')->textInput(['maxlength' => 255,'placeholder'=>' '])->label(' ') ?> </div> <div class="form-group" style="margin-left: 50px;"> <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> </div> <?php ActiveForm::end(); ?>