3

Here is my code:

public function actionPostTest()
{

    if(isset($_POST['Test']))
    {
        $model = new Test();
        $model->attributes = $_POST['Test'];
        if($model->save())
        {
            $this->redirect('postTest');
        }
    }

    $this->render('posttest', array('model'=>new Test()));
}

This is saving the data which coming from a form twice to the database.

What is wrong?

2 Answers2

4

Try disabling ajax validation.

Set enableAjaxValidation to false in that view.

Actually there POST happens two times. First Ajax validation and second form submit. You can confirm it by using httpfox in firefox.

Harikrishnan
  • 9,688
  • 11
  • 84
  • 127
  • @Harikrishnan...you are right...but i needed that ajax validation and changed it a little and it is working fine now. Thanks) –  May 22 '14 at 16:55
  • sorry bro) I am new here...dont know all the details) –  May 22 '14 at 17:01
0

You can try by this

$model = new Test();
if(isset($_POST['Test']))
{       
    $model->attributes = $_POST['Test'];
    if($model->save())
    {
        unset($_POST['Test']);
        $this->redirect('postTest');
    }
}
MH2K9
  • 11,951
  • 7
  • 32
  • 49