dqwd71332 2013-11-27 10:45
浏览 16
已采纳

它没有验证我的表单数据

i have form like this

my form

  <?php

   $error = $model->getErrors();
   print_r($error);

   <form method="post" action="<?php echo Yii::app()->getBaseUrl(true).'/index.php/admin/user/resetpassword'?>" enctype="multipart/form-data">
     <div class="row">
       <label>Old Password</label><input type="password" name="oldpassword" value="<?php echo $model->email; ?>"/><span><?php if(isset($error['email'])) echo $error['email'][0]; ?></span>
    </div> 
    <div class="row">
      <label>New Password</label><input type="password" name="newpassword"/><span><?php if(isset($error['password'])) echo $error['password'][0]; ?></span>
    </div>
    <div class="row">
      <label>Repeat Password</label><input type="password" name="repeatpassword" value="<?php echo $model->employeeid; ?>"/><span><?php if(isset($error['employeeid'])) echo $error['employeeid'][0]; ?></span>
    </div>
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Reset Password' : 'Save'); ?>
 </form>

my model class is

   class User extends CActiveRecord
   {
    public $oldpassword;
    public $newpassword;
    public $repeatpassword;
    /**
 * @return string the associated database table name
 */
public function tableName()
{
    return 'user';
}
    /**
 * @return array validation rules for model attributes.
 */
public function rules()
{
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
        array('email, password, employeeid, designation, manager, profilepic', 'required','except'=>'resetpassword'),
                   array('email','email'),              array('profilepic','file','types'=>'jpg,jpeg,png','allowEmpty'=>true,'on'=>'update'),
                    array('email,employeeid','unique'),
                    array('newpassword, repeatpassword, oldpassword','required','on'=>'resetpassword'),
                    array('repeatpassword','compare','compareAttribute'=>'newpassword','on'=>'resetpassword'),

        array('email, password, employeeid, designation, manager, profilepic', 'safe', 'on'=>'search'),
    );
}

my controller function

     public function actionResetPassword()
    {
        $model = new User('resetpassword');

        if(Yii::app()->request->isPostRequest)
        {
            if($model->validate())
                $this->redirect(array('resetpassword','msg'=>'Password successfully changed..'));
        }
        $this->render('resetpassword',array('model'=>$model));
    }

it always giving error say "oldpassword,repeatpassword,newpassword required" even though have entered value..

can anybody help me pls

Thanks in advance

  • 写回答

2条回答 默认 最新

  • doupike2351 2013-11-27 10:51
    关注

    it's because you are not assigning form value to model variable...

    try this in your controller

       if(Yii::app()->request->isPostRequest)
            {
                $model->oldpassword=$_POST['oldpassword']; //will set to model variable
                $model->newpassword=$_POST['newpassword'];
                $model->repeatpassword=$_POST['repeatpassword'];
                if($model->validate())
                    $this->redirect(array('resetpassword','msg'=>'Password successfully changed..'));
            }
    

    hope it may solve your problem

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大