PHPIN.NET

 找回密码
 立即注册
查看: 9092|回复: 1

[基础应用] YII2.0 Activeform表单组件的使用方法

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2015-3-19 22:13:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
YII2.0 Activeform表单组件的使用方法

Activeform
文本框:textInput();
密码框:passwordInput();
单选框:radio(),radioList();
复选框:checkbox(),checkboxList();
下拉框:dropDownList();
隐藏域:hiddenInput();
文本域:textarea(['rows'=>3]);
文件上传:fileInput();
提交按钮:submitButton();
重置按钮:resetButton();

  1.             <?php $form = ActiveForm::begin(['action' => ['test/getpost'],'method'=>'post','id' => 'reg-form',]); ?>
  2.                 <?= $form->field($model, 'username')->textInput(['maxlength' => 20]) ?>
  3.                 <?= $form->field($model, 'password')->passwordInput(['maxlength' => 20]) ?>
  4.                 <?= $form->field($model, 'sex')->radioList(['1'=>'男','0'=>'女']) ?>
  5.                 <?= $form->field($model, 'edu')->dropDownList(['1'=>'大学','2'=>'高中','3'=>'初中'],['prompt'=>'请选择','style'=>'width:120px']) ?>
  6.                 <?= $form->field($model, 'file')->fileInput() ?>
  7.                 <?= $form->field($model, 'hobby')->checkboxList(['0'=>'篮球','1'=>'足球','2'=>'羽毛球','3'=>'乒乓球']) ?>
  8.                 <?= $form->field($model, 'info')->textarea(['rows'=>3]) ?>
  9.                 <?= $form->field($model, 'userid')->hiddenInput(['value'=>3]) ?>
  10.                 <?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
  11.                     'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
  12.                 ])->label('验证码',['class' => 'key']) ?>
  13.                 <?= Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>   
  14.                 <?= Html::resetButton('重置', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>
  15.             <?php ActiveForm::end(); ?>
复制代码

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
 楼主| 发表于 2015-9-15 13:30:45 | 显示全部楼层
radioList横排:
  1. <?= $form->field($model, 'sex')->inline(true)->radioList(['1'=>'男','0'=>'女']) ?>
复制代码

checkboxList横排:
  1. <?= $form->field($model, 'hobby')->inline(true)->checkboxList(['0'=>'篮球','1'=>'足球','2'=>'羽毛球','3'=>'乒乓球'])?>
复制代码

textInput添加placeholder:
  1. <?= $form->field($model, 'name')->textInput(['placeholder' => 'name']) ?>
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-19 01:23

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表