Yii Framework Forum: How To Call Ajax - Yii Framework Forum

Jump to content

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • You cannot start a new topic
  • You cannot reply to this topic

How To Call Ajax Rate Topic: *---- 1 Votes

#41 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 21 May 2013 - 10:21 PM

Sir, i tried like this also, but action is not working. when i remove htmlOptions in password file then action is working, but the page is displaying on next page.
0

#42 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 10:23 PM

Hi

can u send me your code please ?
Thanks,
Ankit Modi
Skype : amodi06
0

#43 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 10:35 PM

hi

u can try the code in ur password page
<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        
        'id' => 'changePass-form',
	'action'=>'password'
        'type' => 'horizontal',
        'enableAjaxValidation' => false,
        'clientOptions' => array(
                'validateOnSubmit' => true,
		'afterValidate' => 'js:checkErrors'

            ),
        'htmlOptions' => array(
                'onsubmit' => "return false;",
            ),


    ));
    ?>

<script>
                function checkErrors(form, data, hasError) {
                    var data=$("#changePass-form").serialize();
                    if(hasError!=true){
                        $.ajax({
                            type: 'POST',
                            url: '<?php echo Yii::app()->createAbsoluteUrl("user/password?id="); ?>',
                            data:data,
                            asyc:false,
                            success:function(data){
                               alert(data);
                               

                            }

                        });
                    }
                }
</scritp>

Thanks,
Ankit Modi
Skype : amodi06
0

#44 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 21 May 2013 - 10:46 PM

Now it's working. thank you.......
0

#45 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 10:52 PM

ok good try..

what's problem in my code?
Thanks,
Ankit Modi
Skype : amodi06
0

#46 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 11:17 PM

plese send the code
Thanks,
Ankit Modi
Skype : amodi06
0

#47 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 11:36 PM

please uncomment the code in your rules and try the page

array('pass2', 'compare', 'compareAttribute' => 'pass1', 'on' => 'resetPass, changePassword'),

and comment the code
// array('pass1, pass2', 'application.components.validate.EPasswordStrength', 'on' => 'resetPass, changePassword'),

Thanks,
Ankit Modi
Skype : amodi06
0

#48 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 11:38 PM

if below is not working

so u can change the action code in below.

 public function actionPassword($id) {

        $user = app()->user->getUser();
        if (isset($user->id) && $user->id === $id || app()->user->isAdmin()) {
            $model = $this->loadModel($id);
            $model->setScenario('changePassword');
            if (isset($_POST['User'])) {
			if((count(CJSON::decode(CActiveForm::validate($model)))>0)) {
				$this->render('/user/password',array(
						'model'=>$mode,
				));
				Yii::app()->end();
			}
                $model->attributes = $_POST['User'];
                if ($model->validate()) {
                    $model->password = crypt($_POST['User']['pass1'], Randomness::blowfishSalt());
                    if ($model->save()) {
                        app()->user->setFlash('success', 'Saved new password!');
                        $this->redirect(array('user/setting'));
                        //$this->redirect(array('update', 'id' => $model->id));
                        //$this->redirect('view');
                    }
                }
            }

            //$this->render('/user/password', array('model' => $model));
//            $this->renderPartial('/user/password', array('model' => $model),false,true);
        } else {
            // access denied for this user
            throw new CHttpException(403, 'Access Denied.');
        }
         $this->renderPartial('/user/password', array('model' => $model),false,true);
    }



Thanks,
Ankit Modi
Skype : amodi06
0

#49 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 21 May 2013 - 11:54 PM

also u can try

public function actionPassword($id) {


		$model=Users::model()->findByPk((int)$id);
		$model->setScenario('changePassword');
		if (isset($_POST['User']) && !empty($_POST['User'])) {
			if((count(CJSON::decode(CActiveForm::validate($model)))>0)) {
				$this->render('/user/password',array(
						'model'=>$mode,
				));
				Yii::app()->end();
			}
			$modelForm->password_repeat = $data['User']['password_repeat'];

			$model->password=md5($modelForm->password_repeat);
			$model->save(false);


			if (!$model->hasErrors()) {
					
				Yii::app()->user->setFlash('success', "Password change successfully!");
				//$this->redirect(array('admin','id'=>$id));
				$this->redirect(array('admin'));
			}else {
				Yii::app()->user->setFlash('error', "Password change failure!");
				//$this->redirect(array('admin','id'=>$id));
				$this->redirect(array('admin'));
			}



			$this->renderPartial('/user/password', array('model' => $model),false,true);
		}




	}

Thanks,
Ankit Modi
Skype : amodi06
0

#50 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 22 May 2013 - 12:12 AM

ok u can try this code

public function actionPassword($id) {

        $user = app()->user->getUser();
        if (isset($user->id) && $user->id === $id || app()->user->isAdmin()) {
            $model = $this->loadModel($id);
            $model->setScenario('changePassword');
            if (isset($_POST['User'])) {
                $model->attributes = $_POST['User'];
                if ($model->validate()) {
                    $model->password = crypt($_POST['User']['pass1'], Randomness::blowfishSalt());
                    if ($model->save()) {
                        app()->user->setFlash('success', 'Saved new password!');
                        $this->redirect(array('user/setting'));
                        //$this->redirect(array('update', 'id' => $model->id));
                        //$this->redirect('view');
                    }else{
				echo "Ssss" ; die;
			}
                }
            }

            //$this->render('/user/password', array('model' => $model));
//            $this->renderPartial('/user/password', array('model' => $model),false,true);
        } else {
            // access denied for this user
            throw new CHttpException(403, 'Access Denied.');
        }
         $this->renderPartial('/user/password', array('model' => $model),false,true);
    }

    

Thanks,
Ankit Modi
Skype : amodi06
0

#51 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 12:17 AM

Again it showing another page. I need same page when i click submit without enter any fields. pls help me.
0

#52 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 22 May 2013 - 12:28 AM

ok it's display from error or not?
if u enter the correct password it's working or not?
Thanks,
Ankit Modi
Skype : amodi06
0

#53 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 12:31 AM

yes, when i enter correct password it's working and it didn't go any page this fine, but when i enter wrong password it showing another page with error like this "fill all the fields".
0

#54 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 22 May 2013 - 12:45 AM

can u post page image when enter a password?(your password layout)
Thanks,
Ankit Modi
Skype : amodi06
0

#55 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 12:50 AM

View PostAnkit Modi, on 22 May 2013 - 12:45 AM, said:

can u post page image when enter a password?(your password layout)

sir, it showing Current Password cannot be blank. like this . i think its not a error. But, Current Password cannot be blank that one also i need show in same page.

Fields with * are required.
Current Password * Current Password cannot be blank.

New Password * New Password cannot be blank.

Confirm Password * Confirm Password cannot be blank.

like this it showing in new page.
0

#56 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 22 May 2013 - 12:55 AM

first u can check the password in your db using setflash messages so u can change the actionpassword

public function actionChangePassword(){
		$id=Yii::app()->customer->id;
		$model=Users::model()->findByPk((int)$id);
		
		if(isset($_POST['user']['oldpassword']) && !empty($_POST['user']['oldpassword']))
		{
			$model->oldpassword=md5($_POST['user']['oldpassword']);
			if($model->oldpassword!=$model->password){
				Yii::app()->user->setFlash('error',Yii::t("messages",'please insert a correct  old password'));
				$this->redirect('user/password',array('model'=>$modelForm));
				Yii::app()->end();
			}else{
				$model->password_repeat=$_POST['user']['password_repeat'];
				$model->password=md5($modelForm->password_repeat);
				$model->save(false);
				if (!$model->hasErrors()) {
					Yii::app()->user->setFlash('error',Yii::t("messages",'Password change a Succesfully..!'));
					$this->redirect('user/password',array('model'=>$model));
					Yii::app()->end();
				}else{
					Yii::app()->user->setFlash('error',Yii::t("messages",'Password change a Failure..!'));
					$this->redirect('user/password',array('model'=>$model));
					Yii::app()->end();
				}
			}

		}
		$this->render('user/password',array('model'=>$model));
	}



and add the password page (it's shuold be set flash message display)

<?php
                foreach(Yii::app()->admin->getFlashes() as $key => $message) {
                    echo '<div class="flash-' . $key . '">' . $message . "</div>\n";
                }
                ?>

Thanks,
Ankit Modi
Skype : amodi06
0

#57 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 01:10 AM

When i did like this my Change Password link(action) is not working.
0

#58 User is offline   Ankit Modi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 883
  • Joined: 19-February 13
  • Location:India

Posted 22 May 2013 - 01:13 AM

ya so please change the name of actionpassword not in actionchangepassword
Thanks,
Ankit Modi
Skype : amodi06
0

#59 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 01:16 AM

i changed it but not working action.
0

#60 User is offline   Devendra411 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 151
  • Joined: 09-April 13
  • Location:Bangalore

Posted 22 May 2013 - 01:39 AM

Dear sir, actually the problem is when i enter correct password and when i click submit the new password is saving to my database and it didn't show any new page. But, when i enter wrong password or without enter any password then i click submit at that time only it showing new page with the message like "fill all fields". But, i need this message also in same page but not in new page.

pls help me. Thank you.
0

Share this topic:


  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 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