CActiveForm didnt save data

Hi, im new in Yii and object oriented.i create and modify the CRUD(create part). The original file only have the empty textfield,First,I want to make the value hardcoded,second,I want it to have the dropdownbox.I already modify it and i am sure that it have the value,but upon saving,it didn’t save into database.Please help me.Tq. :( .

Here is the code.

<div class="form">

<?php $form=$this->beginWidget(‘CActiveForm’, array(‘id’=>‘branch-form’,‘enableAjaxValidation’=>false,)); ?>

&lt;p class=&quot;note&quot;&gt;Fields with &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt; are required.&lt;/p&gt;





&lt;?php echo &#036;form-&gt;errorSummary(&#036;model); ?&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'company_id'); ?&gt;


	&lt;?php //echo &#036;form-&gt;textField(&#036;model,'company_id',array('value'=&gt;&quot;companyname&quot;)); ?&gt;


	&lt;?php 


		&#036;list = CompanyController::companylistname();


		echo &#036;form-&gt;dropDownList(&#036;model,'company_id',CHtml::listData(&#036;list,'id','company_name'));


	?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'company_id'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'branch_name'); ?&gt;


	&lt;?php echo &#036;form-&gt;textField(&#036;model,'branch_name',array('size'=&gt;60,'maxlength'=&gt;100)); ?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'branch_name'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php  &#036;form-&gt;labelEx(&#036;model,'modified_user'); ?&gt;


	&lt;?php  &#036;form-&gt;textField(&#036;model,'modified_user',array('size'=&gt;60,'maxlength'=&gt;100, 'value'=&gt;Yii::app()-&gt;user-&gt;name)); ?&gt;


	&lt;?php  &#036;form-&gt;error(&#036;model,'modified_user'); ?&gt;


&lt;/div&gt; 





&lt;div class=&quot;row&quot;&gt;


	&lt;?php  &#036;form-&gt;labelEx(&#036;model,'modified_date'); ?&gt;


	&lt;?php  &#036;form-&gt;textField(&#036;model,'modified_date',array('value'=&gt;date(&quot;Y-m-d h:i:s&quot;))); ?&gt;


	&lt;?php  &#036;form-&gt;error(&#036;model,'modified_date'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php  &#036;form-&gt;labelEx(&#036;model,'isDelete'); ?&gt;


	&lt;?php  &#036;form-&gt;textField(&#036;model,'isDelete',array('value'=&gt;&quot;0&quot;)); ?&gt;


	&lt;?php  &#036;form-&gt;error(&#036;model,'isDelete'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php  &#036;form-&gt;labelEx(&#036;model,'isActive'); ?&gt;


	&lt;?php  &#036;form-&gt;textField(&#036;model,'isActive',array('value'=&gt;&quot;1&quot;)); ?&gt;


	&lt;?php  &#036;form-&gt;error(&#036;model,'isActive'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row&quot;&gt;


	&lt;?php  &#036;form-&gt;labelEx(&#036;model,'data_version'); ?&gt;


	&lt;?php  &#036;form-&gt;textField(&#036;model,'data_version',array('value'=&gt;&quot;1&quot;)); ?&gt;


	&lt;?php  &#036;form-&gt;error(&#036;model,'data_version'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row buttons&quot;&gt;


	&lt;?php echo CHtml::submitButton(&#036;model-&gt;isNewRecord ? 'Create' : 'Save'); ?&gt;


&lt;/div&gt;

<?php $this->endWidget(); ?>

</div><!-- form -->

You have to paste here controller’s action for this form and companylistname().

Hi, here is something weird, if I put echo at the front, it can save the data. Can i know why?

<div class="row">

<?php echo $form->labelEx($model,‘modified_date’); ?>

<?php echo $form->textField($model,‘modified_date’,array(‘value’=>date(“Y-m-d h:i:s”))); ?>

<?php echo $form->error($model,‘modified_date’); ?>

</div>

but this one cant save the data:-

<div class="row">

<?php $form->labelEx($model,‘modified_date’); ?>

<?php $form->textField($model,‘modified_date’,array(‘value’=>date(“Y-m-d h:i:s”))); ?>

<?php $form->error($model,‘modified_date’); ?>

</div>

Thanks. :)

Awww… I didn’t see that. Yes, you need to echo these. Form methods return strings but don’t display them. See CActiveForm class.

Bizley,thank you very much.I solve it by adding style="display:none;" at the div block.

However, I still got problem on the dropdownlist, it have the data upon selection but when we create it, it still save as an empty.

here is the code:

controller:-

public function companylistname()

{


	&#036;list = Branch::model()-&gt;findAll(array(


			'select' =&gt; 'branch_name',


		));


	return &#036;list;


}

view:-

<div class="row">

	&lt;?php echo &#036;form-&gt;labelEx(&#036;model,'Company Name'); ?&gt;


	&lt;?php 


		&#036;list = BranchController::companylistname();


		echo &#036;form-&gt;dropDownList(&#036;model,'parent_id',CHtml::listData(&#036;list,'id','branch_name'));


	?&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model,'parent_id'); ?&gt;


&lt;/div&gt;

You’ve got static call for nonstatic method companylistname. Also check your Branch findAll method if it’s correct.