0
votes

Hello World!
i am trying to add the DateTimePicker widget to my active form but i am getting null every time in the database in that field, i don't know why i tried to change the format but it's not working any thoughts please?

View

<?php echo DateTimePicker::widget(
    [
        'model' => $data['model'],
        'attribute' => 'expire_date',
        'options' => ['placeholder' => 'Select operating time ...'],
        'convertFormat' => true,
        'pluginOptions' => [
            'format' => 'y-m-d h:m:s',
          //  'startDate' => '01-Mar-2014 12:00 AM',
            'todayHighlight' => true
    ]
]
)?>



Controller

 public function actionAddjob()
    {
        if(!Yii::$app->user->isGuest){
            $data['model'] = new Job();
            return $this->render('addjob', compact('data'));
        } else {
            $this->goHome();
        }

    }
2

2 Answers

1
votes

Which DateTime picker you are using? I think you have given the wrong date format. Try this

<?php echo DateTimePicker::widget(
    [
        'model' => $data['model'],
        'attribute' => 'expire_date',
        'options' => ['placeholder' => 'Select operating time ...'],
        'convertFormat' => true,
        'pluginOptions' => [
            'format' => 'yyyy-mm-dd hh:ii:ss'
            'todayHighlight' => true
    ]
]
)?> 

This should work.

0
votes

Use your datepicker on $form object like this:

<?= $form->field($model, 'expire_date')->
            widget(DateTimePicker::classname(), [
                'options' => ['placeholder' => 'Select operating time ...'],
                'pluginOptions' => [
                   'format' => 'y-m-d h:m:s',
                    'todayHighlight' => true,
                    'class' => 'form-control'
                ]
            ]);
            ?>

This is because I am not sure whether name property for your filed is set.

I do not found controllers relevant code in your question.

Try to match your controller code with this:

if ($model->load(Yii::$app->request->post())){

echo "<pre>";print_r($model->expire_date);die();
}

you will get expire_date printed on your screen