Hi, friends
I have a dialog for update ordering which contain _form_update.php.
why i can’t post[‘oldproduct’] and post[‘newproduct’] from _form_update.php.
view: main.php
function onChangeUpdate_order(changeVal) {
$('#dialogUpdateOrder').dialog('open');
var update_order_id=changeVal.value;
<?php echo CHtml::ajax(array(
'url'=>array('/Order/Update/','id'=>120),
'data'=>"js:{order_id:update_order_id}",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if (data.status == 'failure')
{
$('#dialogUpdateOrder div.divFormUpdate').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#dialogUpdateOrder div.divFormUpdate form').submit(onChangeUpdate_order);
}
else
{
$('#dialogUpdateOrder div.divFormUpdate').html(data.div);
setTimeout(\"$('#dialogUpdateOrder').dialog('close') \",1000);
}
} ",
));
?>
return false;
}
view: _form_update.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'order-form-update',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'customer_id'); ?>
<?php echo $form->dropDownList($model,'customer_id',CHtml::listData(Customers::model()->findAll(),'customer_id','fullname'),
array('empty' => '--- Choose---')); ?>
<?php echo $form->error($model,'customer_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'order_status'); ?>
<?php echo $form->textField($model,'order_status'); ?>
<?php echo $form->error($model,'order_status'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'address'); ?>
</div>
<script type="text/javascript">
function addProductonupdate() {
var ni = document.getElementById('divProduct');
var numi = document.getElementById('countLastInput');
var num = (document.getElementById('countLastInput').value -1)+ 2;
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = num;
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = <?php echo $form->dropDownList(OrderDetail::model(),'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---','name'=>'newproduct[]')); ?>+<?php echo $form->textField(OrderDetail::model(),'qty', array('name'=>'newqty[]')); ?>+'<a href="#" onclick="removePhoto('+divIdName+')">Remove</a>';
ni.appendChild(newdiv);
}
function removePhoto(divNum) {
var d = document.getElementById('divProduct');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
var minus=document.getElementById('countLastInput').value;
document.getElementById('countLastInput').value=minus-1;
}
</script>
<input type="button" name="service_photo" value="Add Product" class="Allbutton" onclick="addProductonupdate();" />
<input type="hidden" value="0" id="countLastInput" name="countLastInput" />
<div id="divProduct">
<?php
foreach ($orderdetail as $i=>$valueorderdetail):
$orderDetailId= $valueorderdetail['order_detail_id'];
$productname=Products::model()->findAllByPk($valueorderdetail['product_id']);
echo '<br>'.$form->dropDownList($valueorderdetail,'product_id',CHtml::listData(Products::model()->findAll(),'product_id','product_name'),
array('empty' => '--- Choose---','name'=>'oldproduct[]'));
echo $form->textField($valueorderdetail,'qty', array('name'=>'oldqty[]'));
echo CHtml::link('Remove',"#", array("submit"=>array('deleteorder', 'id'=>$orderDetailId), 'confirm' => 'Are you sure you want to remove ?'));
endforeach;
?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
controller: actionUpdate
public function actionUpdate($id)
{
if(isset($_POST['order_id']))
$date=date('y-m-d');
$model=$this->loadModel($id);
$issave=false;
$newproductissave=false;
$orderdatilIsSave=false;
$product=new Products();
$orderdetail=OrderDetail::model()->findAll(array("condition"=>'order_id='.$_GET['id']));
if(isset($_POST['oldproduct'])){//Update On old Products
$newOrderdetail=new OrderDetail();
$issave=true;
//Create New product order of update panel
if(isset($_POST['newproduct'])){
$newproduct=$_POST['newproduct'];
$newqty=$_POST['newqty'];
$orderdetailmodel = new OrderDetail;
$newproductissave=true;
}
}
if(($issave)||($newproductissave)){
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'success',
'div'=>"Order successfully updated"
));
exit;
}
else{
$this->redirect(array('view','id'=>$model->order_id,'sql'=>$this->sql));
}
}
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'failure',
'div'=>$this->renderPartial('_form_update', array('model'=>$model,'orderdetail'=>$orderdetail,'product'=>$product), true)));
exit;
}
}
please help me to resolve this problem.
thanks in advance.