Developement

Hi can anyone help me building multiple dependent dropdownlist box. I tried alot but didnt getting the concept can anyone tell me what is the concept behind implementing it and how it works.

Hi vipul,

Here is my code which i have return for depending drop downlist.




 <div class="lgn_top">

					<div class="lgn_top_left"><?php echo $form->labelEx($model,'state_id'); ?>:</div>

					<div class="lgn_top_right">

						<?php echo $form->dropDownList($model,'state_id',$stateList,

			                    array(

			                        'ajax' => array(

			                        'type' => 'POST',

			                        'url' => CController::createUrl('city/citylist'),

			                        'update' => '#Event_city_id'

			                    ),'prompt'=>'Please Select State','class'=>"inpt_drp"

			                )

			            );

			           ?>

						<?php echo $form->error($model,'state_id'); ?>

					</div>

				</div>


				<div class="lgn_top">

					<div class="lgn_top_left"><?php echo $form->labelEx($model,'city_id'); ?>:</div>

					<div class="lgn_top_right">

					    <?php //echo $form->dropDownList($model,'city_id',$cityList, array('prompt'=>'Please Select City','class'=>"inpt_drp"));?>

					    <?php echo $form->dropDownList($model,'city_id',$cityList,

			                    array(

			                        'ajax' => array(

			                        'type' => 'POST',

			                        'url' => CController::createUrl('eventvenue/venuelist'),

			                        'update' => '#Event_venue_id'

			                    ),'prompt'=>'Please Select City','class'=>"inpt_drp"

			                )

			            );

			           ?>

						<?php echo $form->error($model,'city_id'); ?>

					</div>

				</div>


				<div class="lgn_top">

					<div class="lgn_top_left"><?php echo $form->labelEx($model,'venue_id'); ?>:</div>

					<div class="lgn_top_right">

					    <?php echo $form->dropDownList($model,'venue_id',$vanueList, array('prompt'=>'Please Select Venue','class'=>"inpt_drp"));?>

						<?php echo $form->error($model,'venue_id'); ?>

												?>

					</div>

				</div>







And this is an example code in a controller file




public function actionCitylist(){


     	$this->layout="";

		$state_id = $_POST['Event']['state_id'];

	    $cityList = CHtml::listData(City::model()->findAll(array('order'=>'cityname ASC', 'condition'=>"state_id = $state_id")), 'id', 'cityname');


	  echo CHtml::tag('option',

                   array('value'=>''),CHtml::encode('Please Select City'),true);

       foreach($cityList as $value=>$name)

        {

          echo CHtml::tag('option',

                   array('value'=>$value),CHtml::encode($name),true);

        }

	}




I hope you got everything now…try to read this code. and i am sure you will definitely get rid from this prob. ;)

Cheers !!

Thank you Jayant. Its Working fine.

Hello Friends,

        I need your help. I want to insert more than one row into one table at a time. How to make it possible can you help me out to come out of this problem. Its very Urngent.

Can you please elaborate it little bit more.so that i can give any idea to you…

To insert a multiple records in the same table at a same time then you can call a


 $model->save()

method in a loop.It will insert a multiple records in a table.and to get a inserted record id then you can check it with printing a


$model->id

.

I have Html table in my form. User will fill data in that table in the text boxes provided. No. of text boxes is dynamic. and the table in which I want to insert dont have primary key has foreign key. Now my question is foreach loop will be run till.? how to get the No. of rows in the table. Users can add rows in the html Table. So m not getting loop will run till?

hmmm…Ok, that is fine.you can check a $_POST array.and before that create a texfields with some random unique id.and send a total no. of fields which are present in a table.

And run a for loop instant of Foreach here.

Its not a too difficult to do this kind of task.try to implement this solution.hope you that will be a use full thing for you.since,i have done this kind of things lots of time in my projects.:P

can u provide me an example code …please

Hello can anyone help me. I have a listbox. I want to add the selected items of listbox to the dropdownbox. means the numbers of items in drop down must be same as the selected items in the listbox. Its very urgent please help me.




$cnt = $_POST['total'];

				for($i=0;$i<=$cnt;$i++){

					if($_POST['field'.$i]){

						$model->field=$_POST['field'.$i];

						$model->save();


					}



this kind of code you need to write in your action.and i am assuming that you that what you need to write in a view file.

well i have not tested it at my end but i think it will work for you. since i have used this kind of in many of my cakephp projects and it is working fine.but not used yet with Yii app.

But it doesn’t matter that what platform we are using.it’s just a logical approach.so a syntax is not a big issue here.

and if you want to compare this code with my cakephp code then here is my cakephp code.




	$cnt = $this->data['Prepaidlunchdinner']['cnt'];

				for($i=0;$i<=$cnt;$i++){

					if($this->data['Prepaidlunchdinner']['check'.$i]){


						 $this->data['Prepaiddetail']['prepaidlunchdinner_id'] = $prepaidlunchdinner_id;

						 $this->data['Prepaiddetail']['menucat_id'] = $this->data['Prepaidlunchdinner']['menucat'.$i];

						 $this->data['Prepaiddetail']['menuitem_id'] = $this->data['Prepaidlunchdinner']['menuitem'.$i];

						 $this->data['Prepaiddetail']['quantity'] = $this->data['Prepaidlunchdinner']['qty'.$i];

					$this->Prepaiddetail->create();

                                               $this->Prepaiddetail->save($this->data);

						

					}



there is just difference of syntax.But the approach is same here.

I hope this time it will be more clear to you.

There is just

ohhh…why you don’t tell this thing before…





	<div class="row">

			<?php echo $form->labelEx($model,'venuevibe'); ?>

			<?php echo CHtml::checkBoxList('Eventvenue[venuevibe]', $venuevibeselected, $venuevibe,array('template'=>'<div style=width:125px;><div class=chckboxlist>{label}</div><div style=float:left;>{input}</div></div><div class=cleared></div>'));?>

			<?php echo $form->error($model,'venuevibe'); ?>

		</div>







Where $venuevibeselected is a selected values which you can set from a controller action and $venuevibe is a option values.



Now if you want to add these values to database then leave blank at the position of $venuevibeselected like ‘’ which is a array.

above given code will work for a update case.

and you need to do something like this




if(count($_POST['Eventvenue']['venuevibe'])>0)

				     $venuevibe = implode(",",$_POST['Eventvenue']['venuevibe']);

				else

				     $venuevibe = '';


			$_POST['Eventvenue']['venuevibe'] = $venuevibe;



to add it in the database at the time of add.

and to retrieve it on the time of update

just expload this value and passed to the view in array form.that it.

its working on my current project.

and remember all the checkbox values are inserting in a one database field with a comma separated value.

Now everything i have explain you and also given you the code…you can use it.

I know its very silly question but m not getting.

Have you tried my given code for listcheckbox…

Jayant : Did you exactly understood what I want to do.? I need to add all selected values of a ListBox to the DroPDownbox.

So, Why you are not creating a drop down with a seleted values from listbox.

on that page like this





echo $form->dropDownList($model,'attribute',$venuevibeselected, array('prompt'=>'select')); ?>



And if you want to get more clear solution then post your whole requirement here.then we’ll see what else we can do.

I have attached screenshot of my page …and arrow marked the listbox to dropdownbox . I want to add all items which are selected in listbox to the indicated drop down. and similarly that table will contain more dropdown in other rows so these listbox selected items should get added to all dropdowns . even if i add a new row too.

list box problem solved

I have three tables I want to insert data in these table through ajax on click of button. I have form for it I need to submit data in first and third table on first click and on further click data will be submitted only to the third table. I am doing this because first table has primary key named case_no which is foreign key for second and third table. First and second table can contain case_no only uniquely whereas third table can have multiple entry for same case_no.

Can anyone suggest me how to do this…? and also the funtionality of Ajaxbutton.