hello everyone!
please help me to see:
1.there is a model use 4 parts: title,price,quantity,total.
2.the $model->quantity is a part of form, it could be modify.
3.the view could not display the result of total, the ajax is not act.
please help me!
thank you verymuch!
===========================================================================
controller:
<?php
class SiteController extends FrontController
{
public function actionBuyStep1($id)
{
$data= Posts::model()->findByPk($id); //get model message by id
$model=new BuyStep1Form;
$model->attributes=$_POST[‘BuyStep1Form’];
if(isset($_POST[‘ajax’]) && $_POST[‘ajax’]===‘post’){
$model->quantity = $_GET[‘quantity’];
$model->total = $model->quantity * $model->price;
//action! but it is no effect.
echo CActiveForm::validate($model);
Yii::app()->end();
}
$this->render(‘buyStep1’,array(‘model’=>$model));
}
}
==============================================================================
view:
<?php $form=$this->beginWidget(‘CActiveForm’,array(
‘id’=>‘post’,
‘enableAjaxValidation’=>true,
‘focus’=>array($model,‘quantity’),
‘action’=>Yii::app()->createUrl(‘site/buyStep1’),
)); ?>
<h1>product:
<?php echo $model->title; ?>
</h1>
quantity:
<?php echo $form->textField($model,‘quantity’,array(‘size’=>8,‘maxlength’=>7)); ?>
<?php echo $form->error($model,‘quantity’,array()); ?>
price:
<?php echo $model->price;?>
total:
<?php echo $model->total;?>
======================================================================
model:
<?php
class BuyStep1Form extends CFormModel
{
public $id;
public $productid;
public $price;
public $mobile;
public $quantity=1;
public $total;
public $message;
public $title;
public $discription;
public function rules()
{
return array(
array(‘quantity’, ‘required’),
array(‘mobile’, ‘required’),
array(‘message’, ‘length’,‘min’=>3,‘max’=>300),
);
}
public function attributeLabels()
{
return array(
//‘verifyCode’=>‘Verification Code’,
);
}
}
please help me to see how to use ajax to auto display the result?