Cform Via Ajax

Hi, everybody.

I’m a newbie in yii and try to transmit the form with model to the controller via ajax.

Definition of the model:


<?php

/**

 * Class updateViewModel

 */

class updateViewModel extends CFormModel

{

    public $selectedMethod;

    public function rules()

    {

        return array(

            array('selectedMethod','safe'),


        );

    }

    public function attributeLabels()

    {

        return array(

            'selectedMethod' => 'method'

        );

    }

}

Definition of the controller:


<?php

class TestController extends myController

{

	public function actionIndex()

	{

           $model = new updateVieModel;

           $form = new CForm('application.views.api.updateForm',$model);

           if(Yii::app()->request->isAjaxRequest){

              $test = $model['selectedMethod'];

              die($test);

           }

           else{

              if($form->submitted('update')){

                 $test = $model['selectedMethod'];

                 die($test);

              }

              $this->render('index', array('form'=>$form));

           }

	}

}

Definition of the form config:


<?php

return array(

    'title'=>'Update',

    'elements'=>array(

        'selectedMethod'=>array(

            'type'=>'dropdownlist',

            'items'=>array('m1','m2','m3','m4','m5','m6','m7'),

            'ajax'=>array('type' => 'POST',

                'url'=>Yii::app()->createUrl('myFirstModule/test/index'),

                'update' => '#ddlUpdate'

            ),

            'prompt'=>'select method'

        ),

    ),

    'buttons'=>array(

        'update'=>array(

            'type'=>'submit',

            'label'=>'update',

        ),

    ),

);

definition of the view:


<?php

echo $form;

?>

<br>

<div id=ddlUpdate></div>

By pressing button i see correct selected value. But when I try to use the ddl with ajax, the browser sends the POST-request to the server without the selected value. Сan anyone point me my mistake.

Thanks in advance and sorry for my bad english

UPD:

Issue has been resolved. To form fields filled must call $ form-> submitted (‘updateViewModel’);