北京过客 2011-05-19 16:15:02 12640次浏览 28条回复 1 0 0

像选择性别这样的radio在YII的VIEW里怎么写呀

默认值选男

  • 回复于 2011-05-19 16:16 举报
    default="男"
    
  • 回复于 2011-05-19 16:18 举报
    <?php 
    echo $form->radioButtonList($model,'gender',array('0'=>'男', '1'=>'女')); 
    ?>
    
  • 回复于 2011-05-19 16:25 举报
    <input id="ytUser_type" type="hidden" value="" name="User[type]" />
    <input id="User_type_0" value="0" type="radio" name="User[type]" /> 
    <label for="User_type_0">个人会员</label>
    <br/>
    <input id="User_type_1" value="1" type="radio" name="User[type]" /> 
    <label for="User_type_1">企业会员</label>
    

    中间换行了,能不能让它不换行,还有默认值怎么加

  • 回复于 2011-05-19 16:31 举报

    $htmlOptions的template参数

  • 回复于 2011-05-19 16:37 举报

    默认值怎么搞

  • 回复于 2011-05-19 16:38 举报

    我用模板了还是不能在同一行

  • 回复于 2011-05-19 16:39 举报
    <?php 
    echo $form->radioButtonList($model,'type',array('0'=>'个人会员', '1'=>'企业会员'),array('template'=>'<span class="radio">{input}{label}</span> ','separator'=>'')); 
    ?>
    

    我这样就可以了
    你是不是把span定义CSS了?

  • 回复于 2011-05-19 16:42 举报

    自己定义一下CSS就行啊

  • 回复于 2011-05-19 16:46 举报

    默认值怎么搞

  • 回复于 2011-05-19 16:54 举报
    <?php 
    echo $form->radioButtonList($model,'type',array('0'=>'个人会员', '1'=>'企业会员'),array('template'=>'<span class="radio">{input}{label}</span> ','separator'=>'')); ?>
    

    怎么提交的时候提示“会员类型不可为空白”。这个字段是type,请问哪不对呀

  • 回复于 2011-05-19 17:06 举报
    public $verifyCode;
    public $username;
    public $password;
    public $password2;
    public $regtime;
    public $question;
    public $answer;
    public $type;
    
  • 回复于 2011-05-19 17:07 举报
    public function rules()
    {
      // NOTE: you should only define rules for those attributes that
      // will receive user inputs.
      return array(
        array('username, password, question, answer, type', 'required'),
        array('username, password', 'length', 'max'=>128),
        array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
      );
    }
    public function attributeLabels()
    {
      return array(
        'id' => '用户ID',
        'username' => '用户名',
        'password' => '密码',
        'password2' => '再次输入密码',
        'regtime' => '注册时间',
        'question' => '密保问题',
        'answer' => '密保答案',
        'type' => '会员类型',
        'verifyCode'=>'验证码',
      );
    }
    
  • 回复于 2011-05-19 17:08 举报
    <tr>
    <td width="35%" align="right"><?php echo $form->labelEx($model,'type'); ?>:</td><td><?php echo $form->radioButtonList($model,'type',array('0'=>'个人会员', '1'=>'企业会员'),array('template'=>'<span class="radio">{input}{label}</span> ','separator'=>'')); ?>
    </td><td><?php echo $form->error($model,'type'); ?></td>
    </tr>
    
  • 回复于 2011-05-19 17:08 举报

    全在这了,请帮忙看看哪有错呀

  • 回复于 2011-05-19 17:11 举报

    好像没错

  • 回复于 2011-05-19 17:12 举报
    public function actionReg()
    {
      $model1=new User;
      if(isset($_POST['User']))
      {
        //validate user input and redirect to previous page if valid
        $model1->attributes=$_POST['User'];
        $model1->password=md5($_POST['password']);
        $model1->regtime = time();			
        if($model1->validate())
        {				
          $user=User::model()->find('username=:username',array(':username'=>$_POST['User']['username']));
          if($user==null){
            $model1->save();
            Yii::app()->user->setFlash('reg','感谢您的注册,请登陆');
            $this->refresh();		
          }else{			
            Yii::app()->user->setFlash('reg','用户名已经存在,请换一个用户名,重新注册');
            $this->refresh();
          }	
        }
        if(!empty($model1->errors)
        {
          var_dump($model1->errors);
          die;
        }
        $this->redirect(Yii::app()->user->returnUrl);
      }
      $this->render('reg',array('model'=>$model1));
    }
    

    controller 的

  • 回复于 2011-05-19 17:16 举报
    <tr>
    <td width="35%" align="right"><label for="User_password2">再次输入密码</label>:</td><td><input name="User[password2]" id="User_password2" type="password" /></td><td id=cuowu></td>
    </tr>
    <tr>
    <td width="35%" align="right"><label for="User_type" class="required">会员类型 <span class="required">*</span></label>:</td><td><input id="ytUser_type" type="hidden" value="" name="User[type]" /><span class="radio"><input id="User_type_0" value="0" type="radio" name="User[type]" /><label for="User_type_0">个人会员</label></span> <span class="radio"><input id="User_type_1" value="1" type="radio" name="User[type]" /><label for="User_type_1">企业会员</label></span> </td><td><div id="User_type_em_" class="errorMessage" style="display:none"></div></td>
    </tr>
     
    <tr>
    <td width="35%" align="right"><label for="User_question" class="required">密保问题 <span class="required">*</span></label>:</td><td><select name="User[question]" id="User_question">
    <option value="您母亲的名字是什么">您母亲的名字是什么</option>
    <option value="你就读的第一所学校">你就读的第一所学校</option>
    <option value="你对象的名字">你对象的名字</option>
    </select></td><td><div id="User_question_em_" class="errorMessage" style="display:none"></div></td>
    </tr>
    

    YII自己生成的代码在这

  • 回复于 2011-05-19 17:17 举报

    好像RADIO生成的代码和别的不太一样。怎么回事呀

  • 回复于 2011-05-19 17:33 举报
    $model1->attributes=$_POST['User'];
    

    后面

    var_dump($_POST['User']['type']);die;
    

    看看

您需要登录后才可以回复。登录 | 立即注册