yii2 常用ActiveForm表單樣式用法總結

表單整體輸出樣式

  <?php
    $form = ActiveForm::begin([
        'options' => ['enctype' => 'multipart/form-data', 'class' => 'form-horizontal'],
        'method' => 'post',
    ]);
    $template = ['template' => "{label}\n<div class='col-sm-4'>{input}{hint}</div>\n{error}"];
    $colClass = ['class' => 'col-sm-3 control-label no-padding-right'];
?>

文本框:textInput

 <?= $form->field($model, 'name', $template)
                ->textInput(['maxlength' => true, 'value'=>'123', 'name'=>'user_name'])
                ->label('姓名', $colClass);
            ?>

下拉框:dropDownList

<?php $member_model->member_identity = $value['member_identity'] ;//默認選中的值?>
            <?= $form->field($member_model, 'member_identity', $template)
                ->dropDownList(['1'=>"羣主",'2'=>"代表"],['name'=>'member_identity'])         
                ->label('身份', $colClass)
            ?>

多選框:checkboxList

 <?php $model->id = $ids ;?>
            <?= $form->field($model, 'id', $template)
                ->checkboxList($tags,['name'=>'id'])       
                ->label('標籤', $colClass)
            ?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章