Yii Framework Forum: Validation Not Working On Update - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Validation Not Working On Update Rate Topic: -----

#1 User is offline   awebdeveloper 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 29-September 12

Posted 01 July 2014 - 01:30 PM

Validation is not working.



<?php echo $form->passwordField($model, 'currentpassword', array('class'=>'form-control','required'=>'required', 'value'=>'', 'maxlength'=>'40', 'pattern'=>'[a-zA-Z0-9-]{6,40}', 'title'=>'Password should be 6-40 characters containing a-z and 0-9')); ?>
<?php echo $form->error($model, 'currentpassword'); ?>


<?php echo $form->passwordField($model, 'password', array('class'=>'form-control','required'=>'required', 'value'=>'', 'maxlength'=>'40', 'pattern'=>'[a-zA-Z0-9-]{6,40}', 'title'=>'Password should be 6-40 characters containing a-z and 0-9')); ?>
<?php echo $form->error($model, 'password'); ?>


<?php echo $form->passwordField($model, 'confirmpassword', array('class'=>'form-control','required'=>'required', 'value'=>'', 'maxlength'=>'40',	'pattern'=>'[a-zA-Z0-9-]{6,40}', 'title'=>'Password should be 6-40 characters containing a-z and 0-9')); ?>
<?php echo $form->error($model, 'confirmpassword'); ?>



public function actionChangepassword()
{
	$this->layout = (Yii::app()->request->isAjaxRequest) ? '//layouts/ajax' :  '//layouts/precolumn2';
		

	$model = new User('changepassword');
	$data  = array();
		
	if (isset($_POST['User'])) {

		$model = User::model()->findByPk(Yii::app()->User->getId());
		$model->attributes=$_POST['User'];
		if ($model->save()) {
			$message = array(
					'type' 		=>'success',
					'message'	=>'Password Changed.');
			$data['message'] = $message;
		} 
	}

	$data['model'] = $model;
	$this->render('changepassword',$data);
		
		
	}




public function rules()
{
	// NOTE: you should only define rules for those attributes that
	// will receive user inputs.
	return array(
		array('name, user_type_id', 'required','on'=>'signup'),
		array('name, email', 'length', 'max'=>255),
		array('email', 'required','on'=>array('recover','signup')),
		array('email', 'exists','on'=> 'recover'),
		array('email', 'unique'),
		array('email', 'email'),
		array('user_login_count, user_like_count, user_share_count, user_view_count, user_comment_count, user_rating_count', 'numerical', 'integerOnly'=>true),
		
		array('password', 'length', 'max'=>100),
		array('password, confirmpassword', 'required','on'=>array('signup','resetpassword','changepassword')),
		array('confirmpassword', 'compare', 'compareAttribute'=>'password','on'=>array('signup','resetpassword','changepassword'),'message'=>'Passwords dont match'),
		array('currentpassword', 'compareCurrentPassword','on'=>array('changepassword')),

	);
}

0

#2 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 02 July 2014 - 02:50 AM

I take it the last rule isn't triggered? How does your compareCurrentPassword look like?
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#3 User is offline   awebdeveloper 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 29-September 12

Posted 03 July 2014 - 12:12 PM

No rules were triggered. Issue was here


  $model = new User('changepassword');
  .....
  .....
  $model = User::model()->findByPk(Yii::app()->User->getId());




The second one is overriding the first one and the scenario is getting lost.

Is there a way to say don't save if no scenario
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users