View Display Twice After Render

Hi All,

I try create simple calculator for legal fee calculation. My view will collect input needed then controller will calculate after user click submit button. Finally the controller will render to the same view for the result.

My problem is the view will display after render. Below are my code.

view


<?php /** @var BootActiveForm $form */

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(

    'id'=>'legal-fee-form-legalfee-form',

    'type'=>'horizontal',

)); ?>


<fieldset>


<legend>Legal Fee Calculator</legend>

    

<?php echo $form->textFieldRow($model, 'price', array('input-small', 'prepend'=>'RM')); ?>

<?php echo $form->textFieldRow($model, 'legalfee', array('input-small', 'prepend'=>'RM','disabled'=>true)); ?>

<?php echo $form->textFieldRow($model, 'gst', array('input-small', 'prepend'=>'RM','disabled'=>true)); ?>

<?php echo $form->textFieldRow($model, 'total', array('input-small', 'prepend'=>'RM','disabled'=>true)); ?>

</fieldset>


<div class="form-actions">

    <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit', 'label'=>'Calculate Legal Fee')); ?>

    <?php /*$this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'reset', 'label'=>'Reset'));*/ ?>

</div>


<?php $this->endWidget(); ?>

controller


public function actionLegalfee()

	{

		$model=new LegalFeeForm;

		if(isset($_POST['LegalFeeForm']))

		{

			$model->attributes=$_POST['LegalFeeForm'];

			if($model->validate())

			{	

				if($model->price <=150000)

		 			$model->legalfee = $model->price * 0.01;

				else

				{

					$model->legalfee = (($model->price-150000) * 0.007) + 1500;

				}

				//$model->legalfee = this->calculateLegalFee();

				

				$model->gst = $model->legalfee * 0.06;

				$model->total = $model->legalfee + $model->gst;

				

				//$this->redirect(array('legalfee','model'=>$model));

				$this->render('legalfee',array('model'=>$model));

			}

		}

		$this->render('legalfee',array('model'=>$model));

	}

model


class LegalFeeForm extends CFormModel

{

	public $price;

	public $legalfee;

	public $gst;

	public $total;	

	/**

	 * Declares the validation rules.

	 */

	public function rules()

	{

		return array(

			// name, email, subject and body are required

			array('price', 'required'),

			array('price, legalfee, gst, total', 'numerical', 'integerOnly'=>true),

			);

	}

	

	public function attributeLabels()

	{

		return array(

			'legalfee' => 'Legal Fee',

			'gst' => 'Goverment Tax',

			'total' => 'Total',

		);

	}

}

print screen for duplicate view

3922

after render 2.png

It’s look simple but i can not find the solution. Can anybody help me.

Thanks in advance.

Your Code in controller:




//$this->redirect(array('legalfee','model'=>$model));

$this->render('legalfee',array('model'=>$model));



you also dont need the second line in it…you dont need a redirect or render here…let control go down where you show a render in a function

so your code becomes




//$this->redirect(array('legalfee','model'=>$model));

//$this->render('legalfee',array('model'=>$model));



revised code snippet for your controller:




public function actionLegalfee()

        {

                $model=new LegalFeeForm;

                if(isset($_POST['LegalFeeForm']))

                {

                        $model->attributes=$_POST['LegalFeeForm'];

                        if($model->validate())

                        {       

                                if($model->price <=150000)

                                        $model->legalfee = $model->price * 0.01;

                                else

                                {

                                        $model->legalfee = (($model->price-150000) * 0.007) + 1500;

                                }

                                //$model->legalfee = this->calculateLegalFee();

                                

                                $model->gst = $model->legalfee * 0.06;

                                $model->total = $model->legalfee + $model->gst;

                                

                        }

                }

                $this->render('legalfee',array('model'=>$model));

        }