How To Send Multiple Values To Mysql Tables In Yii

This is Form view code


<?php echo $form->textField($model,'questions[]',array('id'=>"content_#index#_question textBox")); ?>


<?php echo $form->textField($model,'questions[]',array('id'=>"content_#index#_question textBox")); ?>

Here is My Controller


public function actionAdd_quick()


{


    $model=new Question;

    $answers=new Answers;


    if(isset($_POST['Question'],$_POST['Answers']))

    {

        $model->attributes=$_POST['Question'];

        $answers->attributes=$_POST['Answers'];

                foreach ($model['questions'] as $value) {

                    $model->questions = $value;


                }

                $model->save();


            Yii::app()->user->setFlash('add_quick','Thank you for ');

            $this->refresh();


    }

    $this->render('add_quick',array('model'=>$model,'answers'=>$answers));

}

actually my process is have to insert multiple questions and answers,but now only last textbox value is inserted.

how to insert multiple records at single submit…

Hi you want to create a mulitple objects like


foreach ($model['questions'] as $value) {

  $model=new Question; //multiple object


  $model->questions = $value;


}



I hope it’s some help.

Did you use question in ajax tab?

As in your view file, you just have 2 textField that the form just send them to the controller.

Hi Ankit its working!!, Thanks for your help.

Hi Shahcheraghean,FOF thanks for your response for my question i got answer from ANKIT MODI.

I didn’t use ajax tab ,im using jquery for append multiple questions and answers…