Yii Framework Forum: Piece Of Code To Be Run Twice In Ajax Request - Yii Framework Forum

Jump to content

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

Piece Of Code To Be Run Twice In Ajax Request Rate Topic: -----

#1 User is online   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 253
  • Joined: 15-August 12

Posted 19 April 2013 - 09:39 PM

In the if(!$validate) block mail function truly runs once.
I'm wondering why In the if($validate) block mail function runs twice !!!???
The problem raise only in Ajax request and in first time that view page loads. after that the if($validate) block runs once, on the other requests if($validate) block truly runs once.

public function  actionCEmail()
{
    $model = $this->loadModel(Yii::app()->user->id);
    $model->scenario = 'CEmail';

    if(isset($_POST['User'])){
        $model->attributes = $_POST['User'];
        $validate=$model->validate();

        if(Yii::app()->request->isAjaxRequest){
            if(!$validate) {
                $to='test@example.ds';
                $subject='test';
                $message='this is test';
                mail($to,$subject,$message);
                Yii::app()->end();
            }
            if($validate){
                $to='test@example.ds';
                $subject='test';
                $message='this is test';
                mail($to,$subject,$message);
                Yii::app()->end();
            }
        }
    }

    if(Yii::app()->request->isAjaxRequest)
        $this->renderPartial('_cemail',array('model'=>$model),false,true);
    else
        $this->render('update',array('model'=>$model,'form'=>'_cemail'));
}


If you need any information tell me put it.
0

#2 User is online   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 253
  • Joined: 15-August 12

Posted 20 April 2013 - 12:12 AM

Amazed!!!!!!!!!!
Last night i have slept after a very effort for solving the problem. Now that i wake up and test the script again, i've amazed, the if($validate) block works!
It has worked truly until i went to run the if(!$validate) block. After once the if(!$validate) block have ran, the if($validate) block is executed twice. !!!!!!!!!!!!!
0

#3 User is online   msoa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 253
  • Joined: 15-August 12

Posted 20 April 2013 - 10:04 AM

Solved: Reason that the if($validate) block was performed twice was: once when Ajax validation and once again when clicking on ajaxSubmitButton for submitting the form.

Is there a way for distinguish these two from one another? order that to be understood what times clicked on ajaxSubmitButton? or other things?
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