Yii表单控件CActiveForm使用

112 阅读1分钟
在开头加上:
?

1
2
3
4
5
6
7
beginWidget('CActiveForm',array(
'id'=>'contact-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
)); ?>


显示全部错误:
?

1errorSummary($model); ?>


?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
labelEx($model,'name'); ?>//显示label
textField($model,'name',array('size'=>60,'maxlength'=>128)); ?>//显示文本框
textArea($model,'body',array('rows'=>6,'cols'=>50)); ?>//显示文本区域
passwordField($model,'password'); ?>//显示密码框
hiddenField($model,'action',array('value'=>'add')); ?>//显示隐藏域
textField($model,'text',array('size'=>60,'maxlength'=>128)); ?>//显示文本框
passwordField($model,'password'); ?>//显示密码框
fileField($model,'file'); ?>//显示上传域
hiddenField($model,'hidden',array('value'=>'add')); ?>//显示隐藏域
dropDownList($model,'select',array('A'=>'A','B'=>'B','C'=>'C')); ?>//显示下拉框
listBox($model,'select',array('A'=>'A','B'=>'B','C'=>'C'),array('multiple'=>'multiple')); ?>//显示多选下拉框
radioButton($model,'radio',array('value'=>'A')); ?>A//显示一个radio
radioButtonList($model,'radio',array('A'=>'A','B'=>'B','C'=>'C')); ?>//显示多个radio
checkBox($model,'checkbox',array('value'=>'A')); ?>B//显示一个checkbox
checkBoxList($model,'checkbox',array('A'=>'A','B'=>'B','C'=>'C')); ?>//显示多个checkbox
error($model,'name'); ?>//显示单个错误


?

1
2
3
4
5
6
//submit
//image type submit
//reset
//button
www.q-blog.cn'); ?>//link
//image


在最后要加上:
?

1endWidget(); ?>