Yii2 学习内容整理

yii2常用表单处理方法

PHPer 2018-01-16 2434 0 0

创建一个表单须加载 ‘yii\widgets\ActiveForm’ 和 ‘yii\helpers\Html’

ActiveForm::begin() - creates a form instance and  beginning of the form.
ActiveForm::begin() and ActiveForm::end() - All of the content placed between this.

使用别名空间 namespace 用 ActiveForm

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

“的ActiveForm'命名空间是非常重要的创造一个积极的形式和”HTML“命名空间是显示不同的HTML输入字段非常有用。

Active Form Begin And End

<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;

//$form = ActiveForm::begin(); //Default Active Form begin
$form = ActiveForm::begin([
    'id' => 'active-form',
    'options' => [
				'class' => 'form-horizontal',
				'enctype' => 'multipart/form-data'
				],
])
/* ADD FORM FIELDS */
ActiveForm::end();
?>

表单上传的方法

使用输入文本框

//Format 1
<?= $form->field($model,'name'); ?>
//Format 2
<?= $form->field($model, 'name')->textInput()->hint('Please enter your name')->label('Name') ?>

TextArea 文本域

<?= $form->field($model, 'desc')->textarea(); ?>
<?= $form->field($model, 'desc')->textarea()->label('Description'); ?>
<?= $form->field($model, 'desc')->textarea(array('rows'=>2,'cols'=>5)); ?>

Password Input Field

//Format 1
<?= $form->field($model, 'password')->input('password') ?>
//Format 2
<?= $form->field($model, 'password')->passwordInput() ?>
//Format 3
<?= $form->field($model, 'password')->passwordInput()->hint('Password should be within A-Za-z0-9')->label('Password Hint') ?>

We added different type of password input field like password with hint, custom lable....

立即注册

更新于:2022-04-15 21:36:40
    您需要登录后才可以评论。 立即注册
    推荐内容

    怎样使用V2Ray代理和SSTap玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩...

    sstap游戏代理教程 从此玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩虹六...

    BT磁力搜索网站汇总和找不到的资源

    什么是磁力链接,您如何使用?

    Z-Library:全球最大的数字图书馆/含打不开的解决方案/镜像

    使用V2Ray的mKCP协议加速游戏

    v2rayN已停止工作

    【车险课堂】什么是无赔款优待系数ncd,你“造”吗?