Database Insert

Guys I have finally got dependent drop box to work on my form. However, when I press submit the value does not get inserted in the db table. I understand that the code in the form for the dependent dropbox was changed. however the ‘cityId’ matches that in the model.


<div class="row">

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

		<?php echo CHtml::dropDownList('cityId','', array()); ?>

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

	</div>

I am not using echo $form->dropDownList($model,cityId,…);

Is this the problem.

This is the output I get after pressing submit. The dependent dropdown is blank. If I all Null values for cityID in database table, then Null value gets inserted. Here is code from controller function


public function actionCity()

	{

    	

		$data=City::model()->findAll('stateId=:id', 

                  array(':id'=>(int) $_POST['Ticket']['stateId']));

 

    	$data=CHtml::listData($data,'id','name');

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

    	{

        	echo CHtml::tag('option',

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

    	}

	}

	

3144

Screen Shot 2012-08-29 at 10.28.30 PM.png

have a look at the generated html source code and see, what is missing. IMHO you need something like Ticket[cityId]

This is the html source code


<div class="row">

		<label for="Ticket_cityId">City</label>		<select name="cityId" id="cityId"></select>		


	</div>

Figured out the solution. Look at update parameter in array. this solves it. Leaving the post here for others.


<?php echo $form->dropDownList($model,'stateId',CHtml::listData(State::model()->findAll(), 'id', 'name'), array(

					'ajax' => array(

					'type'=>'POST', //request type

					'url'=>CController::createUrl('city'), //url to call.

					//Style: CController::createUrl('currentController/methodToCall')

					'update'=>'#' . CHtml::activeId($model, 'cityId'), //selector to update

						//'data'=>'js:javascript statement' 

					//leave out the data key to pass all form values through

					))); ?>

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

	</div>

	

	<div class="row">

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

		<?php echo $form->dropdownList($model,'cityId',array()); ?>

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

	</div>