Copy and insert form field

Hi! I hope somebody could help me with the problem, which I can’t solve. I have a form with fields from 2 models. I am trying to copy one field and insert it in the database. I managed to solve the filed copy part, but in the database is always inserted only the last value, other options are ignored. I tried to do it with the for loop, and with the script for Tabular input but it just don’t work.

About the application, it is a poll, one model is for the question and some other options and the other one is for the answers, which I would like to copy/add with javascript (this part works). So I would need some help with inserting answers in database. I hope you understand what is the problem :D

Her is the code for the answer field (without JS):




<div class="row">

	<?php echo $form->labelEx($options,'answer'); ?>

	<?php echo $form->textField($options, "answer",array('size'=>60,'maxlength'=>150)); ?>

	<?php echo $form->error($options,'answer'); ?>

</div>



And this is the create function:




public function actionCreate()

	{

		$model=new Questions;

		$options=new PollAnswers;


		// Uncomment the following line if AJAX validation is needed

		$this->performAjaxValidation(array($model, $options));


		if(isset($_POST['Questions'], $_POST['PollAnswers']))

		{

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

			$options->attributes=$_POST['PollAnswers'];

			

			$valid=$model->validate();

			$valid=$options->validate() && $valid;

			if($valid) {

				$model->save();

				$options->question_id = $model->id;

				$options->save();

				$this->redirect(array('view','id'=>$model->id));

			}

		}


		$this->render('create',array(

			'model'=>$model,

			'options'=>$options,

		));

	}



Now, how to insert multiple answers in my database? I think that my problem with all my ideas was how to forward all answer values to the controller and how to handle them in the controller. I would really appreciate your help :unsure:

Maybe multimodelform can help you.

You can take a look at the code of this extension.