Click here to Skip to main content
16,015,218 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
here is my view(form)

Add Answers

textField($model, 'answers[]', array('placeholder' => 'Enter Answer'),array('size' => 60, 'maxlength' => 250)); ?>
error($model, 'answers[]'); ?>
textField($model, 'points[]', array('placeholder' => 'Enter Points')); ?>
error($model, 'points[]'); ?>
<img width="15" height="15" src="baseUrl; ?>/images/admin/green-plus-sign-md.png" alt="pluse" class="plus_position">  <img width="15" height="15" src="baseUrl; ?>/images/admin/green--sign-md.png" class="plus_position">


'btn btn-primary'), ' Save'); ?>
endWidget(); ?>


Action create:

public function actionCreate() {
$model = new Answers;

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


foreach ($_POST['Answers'] as $id => $answer)
{
$model[$id] = new Answers;
$model->attributes = $answer;
$valid = $model[$id]->validate() && $valid;
}
if($valid)
{
foreach ($_POST['Answers'] as $id=>$answer)
{
$model[$id]->question_id = $model->id;
$model[$id]->save(false);
}
$this->redirect(array('index','id'=>$model->id));
}
}


}

$this->render('create', array(
'model' => $model,
));
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900