Yii使用layui中两种展示表单的方式
1使用yii2默认的
<div class="layui-card-body "> <?php $form = ActiveForm::begin([ 'id' => 'msg-form', 'options' => ['class'=>'layui-form'], 'enableAjaxValidation'=>false, 'fieldConfig' => [ 'template' => ' <div class="layui-form-item"> {label} <div class="layui-input-inline"> {input} </div> <div class="layui-form-mid layui-word-aux"> {error} </div> </div>', 'labelOptions' => ['class' => 'layui-form-label'], ] ]); ?> <?php echo $form->field($model, 'username')->textInput(['class' => 'layui-input']); ?> <?php echo $form->field($model, 'password_hot')->passwordInput(['class' => 'layui-input']); ?> <?php echo $form->field($model, 'repass_hot')->passwordInput(['class' => 'layui-input']); ?> <?php echo $form->field($model, 'email')->textInput(['class' => 'layui-input']); ?> <div class="layui-form-item"> <label class="layui-form-label">是否启用</label> <div class="layui-input-block"> <input type="radio" name="status" value="1" title="是" checked=""><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>是</div></div> <input type="radio" name="status" value="0" title="否"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>否</div></div> </div> </div> <div class="layui-form-item"> <label for="L_repass" class="layui-form-label"></label> <?php echo Html::submitButton('新增', ['class' => 'layui-btn']); ?> </div> <?php ActiveForm::end(); ?> </div>
第二种,使用后台模板的
<div class="layui-card-body "> <form class="layui-form" action="<?php echo \yii\helpers\Url::to(['create'])?>" method="post"> <input type="hidden" name="<?= Yii::$app->request->csrfParam; ?>" value="<?= Yii::$app->request->getCsrfToken();?>"> <div class="layui-form-item"> <label for="" class="layui-form-label">用户名</label> <div class="layui-input-inline"> <input type="text" value="<?php echo $model->username; ?>" name="username" placeholder="请输入用户名" class="layui-input" maxlength="16" > </div> <?php if ($model->hasErrors('username')): ?> <div class="layui-form-mid layui-word-aux"><?php echo $model->getFirstError('username'); ?></div> <?php endif;?> </div> <div class="layui-form-item"> <label class="layui-form-label">是否启用</label> <div class="layui-input-block"> <input type="radio" name="status" value="1" title="是" checked=""><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><div>是</div></div> <input type="radio" name="status" value="0" title="否"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><div>否</div></div> </div> </div> <div class="layui-form-item"> <label for="" class="layui-form-label"></label> <div class="layui-input-block"> <button type="submit" lay-submit lay-filter="*" class="layui-btn layui-btn-sm">确定</button> <a href="<?php echo \yii\helpers\Url::to(['index'])?>" class="layui-btn layui-btn-sm">返回</a> </div> </div> </form> </div>