Here is the code
View index.php // the first page in view
<?php echo CHtml::Button('Add',array('ajax' => array( 'type'=>'POST',
'dataType'=>'json', 'data'=>array('listing_type'=>'js:document.getElementById("listing_type").options[document.getElementById("listing_type").selectedIndex].value',
'item_pl'=>'js:document.getElementById("item_pl").value'),
'url'=>CController::createUrl('sell/addList'),
'success'=>'function(data){
if(data.status=="1"){
switch(data.product_type){
case "0":
$("#currency_list").append(data.currency_field);
document.getElementById("currency_pl").value = data.currency_pl;
break;
case "4":
$("#hla_list").append(data.hla_field);
document.getElementById("hla_pl").value = data.hla_pl;
break;
case "5":
$("#item_list").append(data.item_field);
document.getElementById("item_pl").value = data.item_pl;
break;
}
document.getElementById("product_counter").value = data.counter;
$("a#inline").fancybox();
if(data.server=="all" && data.totalServerList > 50){
loadForm(data.totalServerList,data.product_type);
}
}else if(data.status=="2"){
alert("Cannot create duplicate item.");
}else{
alert("Please select all the information.");
}
}',
),)); ?>
view _curForm() Full code
<?php
$prodInfo = $modelC2cProductsListing->getProductInfo($formInfo['prodId'],'0');
echo '<div id="div_'.$formInfo['counter'].'">';
echo '<table width="900" cellpadding="0" cellspacing="0" border="0">';
echo '<tr><td width="30px" align="center" valign="top" style="padding-top:5px;">'.CHtml::CheckBox('cur_'.$formInfo['counter'],'', array ('id'=>'cur_'.$formInfo['counter'],'value'=>'Y',)).'</td>';
if($prodInfo['c2c_products_listing_id']!=""){
echo '<td width="350px" align="left" valign="top" style="padding-top:5px;">'.$formInfo['gameName'].'<br>'.$formInfo['serverFullName'].'<BR>Reference # '.$prodInfo['c2c_products_listing_id'].' - <span style="color:blue">This listing already created</span><br><div id="errorMsg_'.$formInfo['counter'].'"></div>'.CHtml::hiddenField('title_'.$formInfo['counter'],$formInfo['gameName'].'<br>'.$formInfo['serverFullName']).'</td>';
echo '<td width="130px" align="left" valign="top" style="padding-top:5px;">'.CHtml::textField('stock_'.$formInfo['counter'],$prodInfo['available_quantity'],array('id'=>'stock_'.$formInfo['counter'],'class'=>'TextField','size'=>15)).'</td>';
echo '<td width="180px" align="left" valign="top" style="padding-top:5px;">'.CHtml::dropDownList('curCurrency_'.$formInfo['counter'],'',array('RMB' => 'RMB', 'USD' => 'USD'),array('options' => array($prodInfo['products_base_currency']=>array('selected'=>true)))).' '.CHtml::textField('curPrice_'.$formInfo['counter'],$prodInfo['products_price'], array('id'=>'curPrice_'.$formInfo['counter'],'class'=>'TextField',
'size'=>12)).'</td>';
echo '<td width="180px" align="left" valign="top" style="padding-top:5px;">';
$delivery = $modelProductsDeliveryMode->getDeliveryMethod("0");
$splitDm = split(",",$prodInfo['delivery_mode']);
foreach($delivery as $deliveryMethod){
$checked = "";
for($i=0;$i<count($splitDm);$i++){
if($splitDm[$i] == $deliveryMethod['products_delivery_mode_id']){
$checked = 'checked';
}
}
echo CHtml::CheckBox($formInfo['counter'].'_dm[]',$checked, array ('id'=>$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dm','value'=>$deliveryMethod['products_delivery_mode_id'],)).'
<span id="'.$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dmText" style="float;left" onClick="checkPm(\''.$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dm\')">'.$deliveryMethod['products_delivery_mode_title'].'</span><br>';
}
}else{
echo '<td width="350px" align="left" valign="top" style="padding-top:5px;">'.$formInfo['gameName'].'<br>'.$formInfo['serverFullName'].'<br><div class="errorMsg" id="errorMsg_'.$formInfo['counter'].'"></div>'.CHtml::hiddenField('title_'.$formInfo['counter'],$formInfo['gameName'].'<br>'.$formInfo['serverFullName']).'</td>';
echo '<td width="130px" align="left" valign="top" style="padding-top:5px;">'.CHtml::textField('stock_'.$formInfo['counter'],'',array('id'=>'stock_'.$formInfo['counter'],'class'=>'TextField','size'=>15)).'</td>';
echo '<td width="180px" align="left" valign="top" style="padding-top:5px;">'.CHtml::dropDownList('curCurrency_'.$formInfo['counter'],'',array('RMB' => 'RMB', 'USD' => 'USD')).' '.CHtml::textField('curPrice_'.$formInfo['counter'],'', array('id'=>'curPrice_'.$formInfo['counter'],'class'=>'TextField',
'size'=>12)).'</td>';
echo '<td width="180px" align="left" valign="top" style="padding-top:5px;">';
$delivery = $modelProductsDeliveryMode->getDeliveryMethod("0");
foreach($delivery as $deliveryMethod){
echo CHtml::CheckBox($formInfo['counter'].'_dm[]','', array ('id'=>$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dm','value'=>$deliveryMethod['products_delivery_mode_id'],)).'
<span id="'.$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dmText" style="cursor:pointer" onClick="checkPm(\''.$formInfo['counter'].'_'.$deliveryMethod['products_delivery_mode_id'].'_dm\')">'.$deliveryMethod['products_delivery_mode_title'].'</span><br>';
}
}
echo'</td>';
echo '<td width="30px" align="center" valign="top"><div style="cursor:pointer;" onClick="removeCurList(\''.$formInfo['counter'].'\')">X</div></td></tr>';
echo '<tr><td height="10px" colspan="6"></td></tr>';
echo '<tr><td height="25px" colspan="6"><div id="errorMsg_'.$formInfo['counter'].'"></div></td></tr>';
echo '<tr><td height="10px" colspan="6"></td></tr>';
echo '</table>';
echo '</div>';
?>
Controller sell/addList
public function actionAddList(){
... code
switch($productType){
case '0': // Currencies
foreach($a as $<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />{ // the foreach loop to create the form
$currency_field .= $this->renderPartial('_curForm',array('modelC2cProductsListing'=>$modelC2cProductsListing,'modelProductsDeliveryMode'=>$modelProductsDeliveryMode,'formInfo'=>$formInfo), true);
}
break;
..... code
echo CJSON::encode(array(
'product_type'=>$productType,
'currency_field'=>$currency_field, // here i return the form in json
));
}
there is bunch of code and i try to collect the part relate to the button.
Each row of the form is going to append in the <div id="currency_field"></div>