[Solved] Submit Result/response From Datepicker To Sql Query


I am learning php using yii framework. Was using vba and sql before so don’t have much knowledge about javascript.

I have a sql query to which I want to pass date using DatePicker. I did the parameter binding and it works if I give values directly to the binded variables. I don’t know how to exactly pass the value after clicking submit button.

In my view I use TbActiveForm and datepicker widgets. So my view.php looks like:


$form = $this->beginWidget(


        'id' => 'inlineForm',

        'type' => 'inline',

        'htmlOptions' => array('class' => 'well'),



Start Date

<?php $this->widget('bootstrap.widgets.TbDatePicker',array(

                     'name' => 'from_date',

                     'id' => 'date1',

                     'value' => '2014-01-01',

                     'options' => array('format' => 'yyyy-mm-dd')



End Date           

<?php $this->widget('bootstrap.widgets.TbDatePicker',array(

                    'name' => 'to_date',

                    'id' => 'date2',

                    'value' => '2014-04-30',

                    'options' => array(

                    'format' => 'yyyy-mm-dd')




   <!-- Submit Button -->   

<?php $this->widget('bootstrap.widgets.TbButton',array(

                    'buttonType' => 'Submit',

                    'label' => 'Submit',

                     'type' => 'primary',




And in the controller I have :from_date and :to_date binded to variables $from and $to respectively. If I provide values to the variables the query works fine so there is no problem in binding. The controller code looks like:


         $from = '2014-01-01';

         $to = '2014-01-28';

       //  $from = $_POST['from_date'];

       //  $to = $_POST['to_date'];

  $sql = "SELECT [Ordernumber]



      FROM [Orders]

      WHERE CAST(Order_Date As Date) BETWEEN :from_date AND :to_date

      ORDER BY Order_Date ";

   $sql2 = "SELECT COUNT(*)

            FROM [Orders]

            WHERE CAST(Order_Date As Date) BETWEEN :from_date AND :to_date";







             $dataProvider = new CSqlDataProvider($sql, array('keyField' => 'Order_Date',


               	'params' => array(

               		':from_date' => $from,

               		 ':to_date' => $to),

               	'totalItemCount' => $command->queryScalar(),


                'pagination' => array(

                	'pageSize' => 20)));


		  $this->render('link',  array('dataProvider' => $dataProvider));


So if I use

$from = $_POST['from_date'];

I get an error undefined index from_date. I want the query to initially return results based on default value of the DatePicker, and if user selects some date range and clicks submit, the result should be based on those dates. So in short I don’t know how to pass the value submit by user in the view to the controller.

you can do a simple if else





Ok it uses the default(else) value… but how do I make it change the query when I set another date and click on submit. Nothing happens when I change the date and click on submit

I want to know what code I have to write for Submit button so it passes that values from DatePicker back to the controller

Can anyone help with this please.

I have added url to the button too… I don’t know if its needed. But still its not working.

<?php $this->widget('bootstrap.widgets.TbButton',array(

                    'buttonType' => 'Submit',

                    'label' => 'Submit',

                     'type' => 'primary',

                     'url' => 'Link'  




Its solved just a silly mistake in button type syntax

I wrote

'buttonType' => 'Submit',

Instead of

'buttonType' => 'submit',

Thanks for all the help guyz.