要使用小部件,可以先到总文件去找   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. 10个经典的 Java main 方法面试题

    以下是笔者认为比较经典的关于Java main方法的面试题,与其说是Java面试题,其实也是Java的一些最基础知识问题,分享给大家,如有错误,请指出. 1.不用main方法如何定义一个类? 不行,没 ...

  2. 2 hive的使用 + hive的常用语法

    本博文的主要内容有: .hive的常用语法 .内部表 .外部表 .内部表,被drop掉,会发生什么? .外部表,被drop掉,会发生什么? .内部表和外部表的,保存的路径在哪? .用于创建一些临时表存 ...

  3. MyEclipe10中集成Tomcat7

    1.MyEclipse|Servers|Tomcat|Tomcat 7.x 2.Enable 3.Browse:D:\Tomcat 7.0 4.JDK:下拉选择JDK7.0,注意:千万不能在此处右键A ...

  4. 用js判断一个复选框是否被选中

    <html> <head>        <title>            复选框全选.全不选.反选.必选一个        </title>    ...

  5. mapreduce 读写lzo文件

    1.读lzo文件 需要添加以下代码,并导入lzo相关的jar包  job.setInputFormatClass(LzoTextInputFormat.class); 2.写lzo文件 lzo格式默认 ...

  6. JDK安装目录下的src

    学Java这么久,JDK目录下的包有哪些都不知道,今天偶然解压到src明白了许多道理 1.进入JDK安装目录,我的安装路径为:E:\JDK\jdk1.8.0,可以看到这里有个src压缩文件 2.直接解 ...

  7. 关于MS office 180天后再次激活遇到的问题解决方法

    遇到的问题: 再次点击miniKMS  激活软件激活失败 : 我也不知道这是为什么?后来我在同一目录重装了一次,点击的还是我以前的那个KSM激活软件,出现的错误还是一样的.于是我想可能是这个激活软件的 ...

  8. Android中的主题Theme

    系统自带的Theme: android以及为我们定义好了一些theme,需要是我们直接可以拿来使用. 常用的Theme通常如下:  android:theme="@android:style ...

  9. Hadoop作业调度器

    随着 MapReduce 的流行,其开源实现 Hadoop 也变得越来越受推崇.在 Hadoop 系统中,有一个组件非常重要,那就是调度器.调度器是一个可插拔的模块,用户可以根据自己的实际应用要求设计 ...

  10. SSL 错误

    javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?    at com.sun.net.ssl.in ...