Unable To Submit Date Using Cjuidatepicker

I’m trying to use the CJuiDatePicket widget to submit a date, but it keeps telling me the field doesn’t have a default value. When I go to update fields it fills the field with the correct date, but it just don’t submit for some reason. Any ideas?


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

<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(

			'model'=>$model,

			'attribute'=>'created',

		'options'=>array(

			'showAnim'=>'fold',

			'dateFormat'=>'yy-mm-dd',

			'changeYear'=>true,

			'changeMonth'=>true,

			'yearRange'=>(date('Y')-1).':'.date('Y'),

			),

		)); ?>

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

Exception:

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1364 Field ‘created’ doesn’t have a default value.

Did you put "created" in the rules

Hello,

Please try with this code :




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

<?php widget('zii.widgets.jui.CJuiDatePicker', array( 

            'model' => $model, 

            'attribute' => 'created', 

            'value' => $model->created, 

            'options' => array( 

                'showButtonPanel' => true, 

                'changeYear' => true, 

                'dateFormat' => 'yy-mm-dd', 

                ), 

            )); 

; ?> 

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



Well it seems to be saving now, although I really didn’t change anything. I need it to display the current date for new records and pull the saved date for updates. Here is what I have that seems to be working. Thanks!


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

<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(

			'model'=>$model,

			'attribute'=>'created',

		'options'=>array(

			'showAnim'=>'fold',

			'dateFormat'=>'yy-mm-dd',

			'changeYear'=>true,

			'changeMonth'=>true,

			'yearRange'=>(date('Y')-1).':'.date('Y'),

		),

		'htmlOptions'=>array('readonly'=>true,

				     'value'=>$model->isNewRecord ? date('Y-m-d') : $model->created,

		),

)); ?>

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