要使用小部件,可以先到总文件去找   framework/yiilite文件里面搜索“CAtiveForm”

(如果觉得小部件的radio布局有点难看,可以在外面定义,具体可以在控制器里面定义)

如下:

function actionRegister(){
            //实例化数据模型
            $user_model=Admin::model();
            $sex[1]='男';
            $sex[2]='女';
            $sex[3]='保密';
            $this->render("register",array("user_model"=>$user_model,"sex"=>$sex));
            
        }  那么在下面的表单中直接可以使用$sex对象了

<?php $form=$this->beginWidget('CActiveForm');?>
                    <table cellpadding="5" cellspacing="3"
                    style="text-align: left; width: 100%; border: 0;">
                    <tbody>
                        <tr>
                            <td style="width: 13%; text-align: right;">
                                    <?php echo  $form->label($user_model,'name')?>
                                    
                                </td>

<td style="width: 87%;">
                                <?php echo $form->textField($user_model,'name', array('class'=>'inputBg()','id'=>'username'));?>
                                <span style="color: red;"></span>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                            <?php echo  $form->label($user_model,'password')?>
                                    <span class="required">*</span>
                            </td>

<td>
                                <?php echo $form->passwordField($user_model,'password', array('class'=>'inputBg()','id'=>'passowrd'));?>
                                </td>
                        </tr>
                          <tr>
                                        <td align="right"><label for="User_password2">密码确认</label></td>
                                        <td>
                                            <input class="inputBg" size="25" name="User[password2]" id="User_password2" type="password" />
                                        </td>

</tr>
                        <tr>
                            <td align="right"><?php echo  $form->label($user_model,'email')?></td>
                            <td>
                                <?php echo $form->textField($user_model,'email', array('class'=>'inputBg()','id'=>'email'));?>
                                </td>
                        </tr>
                        <tr>

<td align="right"><?php echo  $form->label($user_model,'QQ')?></td>
                            <td>
                                <?php echo $form->textField($user_model,'QQ', array('class'=>'inputBg()','id'=>'qq'));?>
                                </td>
                        </tr>
                        <tr>
                            <td align="right"><?php echo  $form->label($user_model,'tel')?></td>
                            <td>
                                <?php echo $form->textField($user_model,'tel', array('class'=>'inputBg()','id'=>'tel'));?>
                                </td>
                        </tr>
                        <tr>
                            <!--radioButtonList($model,$attribute,$data,$htmlOptions=array())-->
                            <td align="right"><?php echo  $form->label($user_model,'sex')?></td>
                            <td>

                <!--------按钮默认<br/>结束 红色地方设置,$htmlOptions值,这样按钮才能在一行------->

            <?php echo $form->radioButtonList($user_model,'sex',$sex),array("separator"=>"&nbsp;")?>
                            </td>
                        </tr>
                        <tr>
                            <!--dropDownList($model,$attribute,$data,$htmlOptions=array())-->
                            <td align="right"><?php echo  $form->label($user_model,'xueli')?></td>
                            <td><select name="User[user_xueli]" id="User_user_xueli">
                                    <option value="1" selected="selected">-请选择-</option>
                                    <option value="2">小学</option>

<option value="3">初中</option>
                                    <option value="4">高中</option>
                                    <option value="5">大学</option>
                            </select>
                                <div class="errorMessage" id="User_user_xueli_em_"
                                    style="display: none"></div></td>
                        </tr>
                        <tr>
                            <!--checkBoxList($model,$attribute,$data,$htmlOptions=array())-->
                            <td align="right"><?php echo  $form->label($user_model,'hoddy')?></td>

<td><input id="ytUser_user_hobby" type="hidden" value=""
                                name="User[user_hobby]" /> <span id="User_user_hobby"> <input
                                    id="User_user_hobby_0" value="1" type="checkbox"
                                    name="User[user_hobby][]" /> <label for="User_user_hobby_0">篮球</label>&nbsp;
                                    <input id="User_user_hobby_1" value="2" type="checkbox"
                                    name="User[user_hobby][]" /> <label for="User_user_hobby_1">足球</label>&nbsp;
                                    <input id="User_user_hobby_2" value="3" type="checkbox"
                                    name="User[user_hobby][]" /> <label for="User_user_hobby_2">排球</label>&nbsp;
                                    <input id="User_user_hobby_3" value="4" type="checkbox"
                                    name="User[user_hobby][]" /> <label for="User_user_hobby_3">棒球</label>
                            </span></td>
                        </tr>
                        <tr>

<!--textArea($model,$attribute,$htmlOptions=array())-->
                            <td align="right"><?php echo  $form->label($user_model,'introduce')?></td>
                            <td><textarea cols="50" rows="5" name="User[user_introduce]"
                                    id="User_user_introduce"></textarea></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>

<td align="left"><input name="Submit" value="提交"
                                class="us_Submit_reg" type="submit" /></td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                    </tbody>
                </table>

<?php $this->endWidget(); ?>

YII 小部件 yii小部件查看方法 小物件做的表单的更多相关文章

  1. JQuery阻止表单提交的方法总结 - 使用onsubmit()验证表单并阻止非法提交

    方法1:<form onsubmit="javascript:confirm()"> 方法内返回false阻止表单提交 示例:代码检测textarea内填写的长度,未填 ...

  2. Yii 通过widget小物件生成添加表单

    通过widget小物件创建添加商品的表单 视图里,表单以endWidget();?>结束 最终效果: 把表单提交过来的信息保存到数据库中去. 补充要点: 密码表单: <?php echo ...

  3. django中ModelForm save方法 以及快速生成空表单或包含数据的表单 包含错误信息

    django中ModelForm学习系列一~save方法 Model代码 from django.db import models # Create your models here. class P ...

  4. vue:父子组件间通信,父组件调用子组件方法进行校验子组件的表单

    参考: ElementUI多个子组件表单的校验管理:https://www.jianshu.com/p/541d8b18cf95 Vue 子组件调用父组件方法总结:https://juejin.im/ ...

  5. 微信小程序相关二、css介绍,菜单制作,表单相关,京东注册页面

    一.第二天上午 1.1上午因为有其他的课所以没有去这个课,不过下午看复习的时候的概括,讲了DTD,语法特性,css选择器以及权重,还有一些简单的样式 1.2 DTD Docuement Type 声明 ...

  6. yii YII小部件 创建登录表单表单 Login表单

    YII框架必须遵循其表单的创建方法 登录模型错做与数据库操作模型是一致的,不同的是不跟数据库交互 ,用的是小部件,在创建表单之前,要在用户控制模块完成以下代码 protected --models - ...

  7. 解决YII提交POST表单出现400错误,以及ajax post请求时出现400问题

    POST表单400错误: 正确做法: Add this in the head section of your layout: <?= Html::csrfMetaTags() ?> -- ...

  8. Yii框架用ajax提交表单时候报错Bad Request (#400): Unable to verify your data submission.

    提交表单报400错误,提示 "您提交的数据无法验证"原来是csrf验证的问题,因为表单是自己写的,在Yii框架中,为了防止csrf攻击,对post的表单数据封装了CSRF令牌验证. ...

  9. Django---form表单提交数据到数据库(普通方法+Django的form类)

    目标: ①.初始form的简单应用 ②.使用Django的form组件完成新增一个帖子 方法一:普通方法 1.前端表单代码 <div> <form class="navba ...

随机推荐

  1. 利用qemu模拟嵌入式系统制作全过程

    http://www.tinylab.org/using-qemu-simulation-inserts-the-type-system-to-produce-the-whole-process/ 利 ...

  2. MongoDB基础知识 02

    MongoDB基础知识 02 6 数据类型 6.1 null : 表示空值或者不存在的字段 {"x":null} 6.2 布尔型 : 布尔类型只有两个值true和false {&q ...

  3. second blog编程之美------控制cpu曲线

    先贴程序: 以前看过这个算法, 不过没什么印象,大概记得它利用while循环来控制cpu利用率 #include int main(int argc,char*argv[]) {         wh ...

  4. MySQL 5.7版本安装教程-踩坑总结

    下载 MySQL下载地址 选择下载64位(看自己电脑是32位还是64位) 点击下载之后,它会让你登录,没有Oracle账户,跟着它的步骤注册一个就好了. 安装 打开下载好的压缩包解压到你的某一目录下, ...

  5. OC封装的TLV数据格式解析库

    作者:朱克锋 邮箱:zhukefeng@iboxpay.com 转载请注明出处:http://blog.csdn.net/linux_zkf TLV是一种可变格式,意思就是: Type类型, Leng ...

  6. shell从函数文件里调用函数

    碰到一个shell中函数调用的小问题,记录一下. shell中函数有三种调用方式,一种是在文件前面定义函数,然后在以下直接调用:一种是通过加载shell,在shell中直接调用:第三种是将函数写入文件 ...

  7. [React] React Fundamentals: Integrating Components with D3 and AngularJS

    Since React is only interested in the V (view) of MVC, it plays well with other toolkits and framewo ...

  8. ||和 && 符号的赋值运用(转)

    javascript “||”.“&&”的灵活运用 博客分类: Jquery javascript javascript中运用“||”.“&&”javascript 真 ...

  9. spring mvc DispatcherServlet详解之interceptor和filter的区别

    首先我们看一下spring mvc Interceptor的功能及实现: http://wenku.baidu.com/link?url=Mw3GaUhCRMhUFjU8iIDhObQpDcbmmRy ...

  10. Vim键盘图与命令图解