Creating A Drop Down List

Hello, I have developed a web application using yii framework. [size="4"]Now i want to add drop down list into my app. This drop down should contain data from another table called "Forms" which is in the same database named "manthan" as using which i have created my app, based on the item in the list i select in drop down list, it should display the data which is in the current table named "Report". How can i relate these two tables in order to achieve above mentioned task? and how can i add a drop down list in my current app. Can somebody please tell me? It will be very helpfull if your responses are in step by step. [/size]

if you use form so you have


echo $form->dropDownList($model,'form_id',Forms::model()->findAll());

or, if you do not use it:


echo CHtml::dropDownList('form_id',Forms::model()->findAll());

http://www.yiiframework.com/doc/api/1.1/CActiveForm/#dropDownList-detail

http://www.yiiframework.com/doc/api/1.1/CHtml/#dropDownList-detail

[size="4"]Hi, i have added a drop down list in my page. it should display data on which item in the list is selected. it contains data of a column field named "FormName".[/size]

Here is my model code:

public function search()

{


	// Warning: Please modify the following code to remove attributes that


	// should not be searched.


	$criteria=new CDbCriteria;


            if(!empty($this->RequestedForm))


            {


	   $criteria->condition = "FormName = $this->RequestedForm";


	}


            $criteria->compare('FormName',$this->FormName,true);


            return new CActiveDataProvider($this, array(


		'criteria'=>$criteria,


    	'pagination'=>false,


	));


}

Here is my controller code:

public function actionSearch()

  {


     $model=new Report('search');  // your model


     $model->unsetAttributes();  // clear any default values


     if(!empty($_POST))


	 {     


  		$model->RequestedForm = $_POST['RequestedForm'];      


	 } 


	//echo "<script>".$model->RequestedForm.";</script>";


if(isset($_GET['Report']))


$model->attributes=$_GET['Report'];


$this->render('admin',array(


		'model'=>$model,


	));


}	

Here is my admin.php in view:

<?php $list=CHtml::listData(Report::model()->findAll(), ‘Id’, ‘FormName’);

echo ‘select a form’;

echo CHtml::dropDownList(‘RequestedForm’, $model->FormName, $list, array(‘empty’ => ‘(Select a state)’,‘onChange’ => ‘submit’,‘submit’ => array(‘report/search’)));?>

[size="4"]but its not displaying accoding to the selected FormName in the drop down list. Can u tell me what am i missing? [/size]

Maybe you need it:




echo CHtml::activeDropDownList($model,'RequestedForm',Report::model()->findAll(), array('empty' => '(Select a state)','onChange' => 'submit','submit' => array('report/search')));



;)

Now all things at single place - http://www.yiiframework.com/wiki/48/by-example-chtml/