I
I
Igor Braduloff2018-08-30 15:51:27
Yii
Igor Braduloff, 2018-08-30 15:51:27

How to get data from DatePicker in Yii2?

Good afternoon! I select the FROM and TO dates of the Datepicker widget, I click on the form button and I want the data from the widget to be substituted as parameters for a query to display a table with data. Tell me how to get data from the DatePicker widget and process it in the controller? how to describe the model?

<?php
            $form = ActiveForm::begin();
            echo '<label class="control-label">Select date range</label>';
            echo DatePicker::widget([
                'model' => $model,
                'attribute' => 'from_date',
                'attribute2' => 'to_date',
                'options' => ['placeholder' => 'Start date'],
                'options2' => ['placeholder' => 'End date'],
                'type' => DatePicker::TYPE_RANGE,
                'form' => $form,
                'pluginOptions' => [
                    'format' => 'yyyy-mm-dd',
                    'autoclose' => true,
                ]
            ]);
      ?>
            <div>
                <button class="btn btn-success" type="submit">Go!</button>
            </div>
       <?php ActiveForm::end(); ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2018-08-30
@slo_nik

// Usage with model and Active Form (with no default initial value)
echo $form->field($model, 'date_1')->widget(DatePicker::classname(), [
    'options' => ['placeholder' => 'Enter birth date ...'],
    'pluginOptions' => [
        'autoclose'=>true
    ]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question