Hello,
I have two partials _shippingAddress and _billingAddress
Both use the $form and on my ajax request, I need to recreate this.
Is there a better way to do this without all this mess?
Thanks
function actionGetAddress() {
$cartForm = new CartForm;
$form=$this->beginWidget('CActiveForm', array(
'id'=>'cart-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($cartForm,'shippingAddress'),
));
$s = ShippingAddresses::model()->find('user_id=:p1', array(':p1' => Yii::app()->user->id));
$cartForm->billingAddress = $s->address1;
$cartForm->billingAddress2 = $s->address2;
$cartForm->billingCity = $s->city;
$cartForm->billingState = $s->state;
$cartForm->billingZip = $s->zip;
$this->renderPartial('_billingAddress', array(
'form'=>$form,
'cartForm' => $cartForm,
));
}
<div class="form">
<?php echo CHtml::ajaxLink('Billing Address same as Shipping Address',array('getAddress'), array('update'=>'#billing')); ?>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'cart-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'focus'=>array($cartForm,'shippingAddress'),
)); ?>
<table width="100%">
<tr>
<td width="50%">
<?php $this->renderPartial('_shippingAddress', array('form'=>$form,'cartForm'=>$cartForm)); ?>
</td>
<td width="50%">
<div id="billing">
<?php $this->renderPartial('_billingAddress', array('form'=>$form,'cartForm'=>$cartForm)); ?>
</div>
</td>
</tr>
<div class="row">
<?php echo $form->labelEx($cartForm,'shippingAddress'); ?>
<?php echo $form->textField($cartForm,'shippingAddress',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'shippingAddress'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'shippingAddress2'); ?>
<?php echo $form->textField($cartForm,'shippingAddress2',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'shippingAddress2'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'shippingCity'); ?>
<?php echo $form->textField($cartForm,'shippingCity',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'shippingCity'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'shippingState'); ?>
<?php echo $form->textField($cartForm,'shippingState',array('size'=>10,'maxlength'=>2)); ?>
<?php echo $form->error($cartForm,'shippingState'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'shippingZip'); ?>
<?php echo $form->textField($cartForm,'shippingZip',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'shippingZip'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'billingAddress'); ?>
<?php echo $form->textField($cartForm,'billingAddress',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'billingAddress'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'billingAddress2'); ?>
<?php echo $form->textField($cartForm,'billingAddress2',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'billingAddress2'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'billingCity'); ?>
<?php echo $form->textField($cartForm,'billingCity',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'billingCity'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'billingState'); ?>
<?php echo $form->textField($cartForm,'billingState',array('size'=>10,'maxlength'=>2)); ?>
<?php echo $form->error($cartForm,'billingState'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($cartForm,'billingZip'); ?>
<?php echo $form->textField($cartForm,'billingZip',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($cartForm,'billingZip'); ?>
</div>