您的位置:首页 > 编程语言 > PHP开发

yii2 常用ActiveForm表单样式用法总结

2017-01-15 03:21 567 查看
表单整体输出样式

<?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)
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  yii2 ActiveForm php