php - password confirmation doesn't work, not defined -
as said in title. got following error message
property "user.repeat_password" not defined.
although have defined in user model.
class user extends cactiverecord { public $repeat_password; /** * @return string associated database table name */ public function tablename() { return 'sys_user'; } /** * @return array validation rules model attributes. */ public function rules() { // note: should define rules attributes // receive user inputs. return array( array('password, repeat_password', 'required', 'on'=>'insert'), array('password, repeat_password', 'length', 'min'=>6, 'max'=>40), array('repeat_password', 'compare', 'compareattribute'=>'password', 'on'=>'create'), array('username', 'length', 'max'=>10), array('isactive', 'safe'), // following rule used search(). // @todo please remove attributes should not searched. array('userid, username, password, isactive, role', 'safe', 'on'=>'search'), ); }
and here view code
<div class="form"> <?php $form=$this->beginwidget('cactiveform', array( 'id'=>'variable-form', 'htmloptions'=>array( 'role'=>'form', ), 'enableajaxvalidation'=>false, )); ?> ... <div class="form-group"> <?php echo $form->labelex($model,'password'); ?> <?php echo $form->passwordfield($model,'password', array('class'=>'form-control input-sm')); ?> <?php echo $form->passwordfield($model,'repeat_password', array('class'=>'form-control input-sm')); ?> <?php echo $form->error($model,'password'); ?> </div> ... <?php $this->endwidget(); ?> </div><!-- form -->
what problem? please help, new yii. should add new column in database?
it because extends cactiverecord. think in table sys_user not exist column repeat_password. how understand want create form validation, fields , processing. need create custom class , extends form . example form:
class registrationform extends cformmodel { /** * @var string */ public $password; /** * @var string */ public $repeat_password; /** * @inheritdoc */ public function rules() { return array( array('password, repeat_password', 'required'), array('password', 'compare', 'compareattribute' => 'repeat_password'), ); } }
how use:
// in controller $form = new registrationform(); if (isset($_post['registrationform'])) { $form->attributes = $_post['registrationform']; $form->validate(); } $this->render('registration', array('model' => $form)); //in view ... <?php echo $form->passwordfield($model,'password', array('class'=>'form-control input-sm')); ?> <?php echo $form->error($model,'password'); ?> <?php echo $form->passwordfield($model,'repeat_password', array('class'=>'form-control input-sm')); ?> <?php echo $form->error($model,'repeat_password'); ?> <?php $this->endwidget(); ?>
Comments
Post a Comment