CJuiDatePicker not saving date in db

367 Views Asked by At

I'm trying to use CJuiDatePicker on a form in yii. The widget looks OK but upon submission, every other form field value gets stored on the db except the date field. What could the problem be?

See my code:

<div class="row">
        <?php echo $form->labelEx($model,'date'); ?>
        <?php //echo $form->dateField($model,'date');
        $this->widget('zii.widgets.jui.CJuiDatePicker',array(
    'model'=>$model,
    'name'=>'date',

    'attribute'=>'date',
    // additional javascript options for the date picker plugin
    'options'=>array(
        'showAnim'=>'fold',
        'dateFormat' => 'yy-dd-mm',
    ),
    'htmlOptions'=>array(
        'style'=>'height:20px;'
    ),
));

         ?>
        <?php echo $form->error($model,'date'); ?>
    </div>
2

There are 2 best solutions below

0
On

check "date" field in model

i use this piece of code in model

public function beforeSave()
{
    if( $this->data )
    {
        $this->data = date('Y/m/d H:i',strtotime(str_replace('/','.',$this->data) ));
    }
    return parent::beforeSave();
}
0
On

Thanks for your contributions. I was ableto fix it. This is the amended code:

<?php //echo $form->dateField($model,'date');
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'date',
                 'value'=>$model->date,
//additional javascript options for the date picker plugin
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'showAnim'=>'fold',
                        'debug'=>true,
'datepickerOptions'=>array('changeMonth'=>true, 'changeYear'=>true),
),
'htmlOptions'=>array('style'=>'height:20px;'),
));

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