Yii Framework Forum: how to save text box from iteration ( Loop) to controller - Yii Framework Forum

Jump to content

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

how to save text box from iteration ( Loop) to controller I have generate text box for "For loop " but I don't know Rate Topic: ***** 1 Votes

#1 User is offline   mrloader 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 06-March 18

Posted 06 March 2018 - 12:30 PM

I have generate text box for "For loop " but I don't know how to save them. and how to send value to controller

my form

<div class="col-md-4">
<?php echo $form->labelEx($model,'paxName'); ?>
<?php echo $form->textField($model,'paxName',array('size'=>60,'maxlength'=>200,'class'=>'form-control','name'=>'paxName['.$i.']','id'=>'paxName['.$i.']')); ?>
<input type='hidden' name='paxName[]'>
<?php echo $form->error($model,'paxName'); ?>
</div>

<div class="col-md-4">
<?php echo $form->labelEx($model,'paxLname'); ?>
<?php echo $form->textField($model,'paxLname',array('size'=>60,'maxlength'=>200,'class'=>'form-control','name'=>'paxLname['.$i.']','id'=>'paxLname['.$i.']')); ?>
<?php echo $form->error($model,'paxLname'); ?>
</div>

<div class="col-md-2">
<?php echo $form->labelEx($model,'paxSex'); ?>
<?php echo $form->textField($model,'paxSex',array('size'=>1,'maxlength'=>1,'class'=>'form-control','name'=>'paxSex['.$i.']','id'=>'paxSex['.$i.']')); ?>
<?php echo $form->error($model,'paxSex'); ?>
</div>



on my controller

public function actionCreate()
{

$model=new Pax;


if(isset($_POST['Pax']))
{


for($i=1;$i<=2;$i++){
$model=new Pax;


//// I try add array but doesn't work
$model->attributes=$_POST['Pax'];
$model->paxName = $paxName[$i];
$model->paxLname= $paxLname[$i];

//// I try add fixed data, It can be saved but the value must get from _from.php
$model->paxSex='1'; //exit;
$model->paxCountry='1'; //exit;
$model->paxDOB='1983-09-01'; //exit;
$model->paxPassportNo='81211212'; //exit;
$model->paxPassportExp='2018-09-08'; //exit;
$model->paxJoin='1'; //exit;
$model->paxRemark='tresdfsfd'; //exit;
$model->paxPrice=850; //exit;
$model->paxBookID='1'; //exit;
$model->paxPassportDoc='4444'; //exit;

// $model->created_at=date('Y-m-d h:i:s');

$model->save();
}
if($model->save())
$this->redirect(array('view','id'=>$model->paxID));
}

$this->render('create',array(
'model'=>$model,
));
}
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