Get data from select2 and pass it to controller in yii2
<p>I've one select2 form field, two datepickers and a search button in productnames index file. It is only to search data I'm unable to get the data selected in the select2 widget and pass it to controller which in turn can search other models.</p>

<p>index.php</p>

<pre><code>&lt;?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\select2\Select2;
use dosamigos\datepicker\DatePicker;
use yii\helpers\ArrayHelper;
use frontend\modules\sbbtdtproduct\models\Productnames;
use yii\helpers\Json;

/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\sbbtdtproduct\models\ProductnamesSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this-&gt;title = 'Productnames';
$this-&gt;params['breadcrumbs'][] = $this-&gt;title;
?&gt;
&lt;div class="productnames-index"&gt;

    &lt;h1&gt;&lt;?= Html::encode($this-&gt;title) ?&gt;&lt;/h1&gt;
    &lt;?php // echo $this-&gt;render('_search', ['model' =&gt; $searchModel]); ?&gt;

    &lt;div class="row"&gt;
        &lt;div class="form-group"&gt;
            &lt;div class="col-xs-5 col-sm-5 col-lg-5" &gt;
                &lt;?php
                    echo Select2::widget([
                    'model' =&gt; $model,
                    'attribute' =&gt; 'productnames_productname',
                    'data' =&gt; ArrayHelper::map(Productnames::find()-&gt;all(),'productnames_productname','productnames_productname'),
                    'options' =&gt; ['placeholder' =&gt; 'Select Product'],
                    'pluginOptions' =&gt; [
                        'allowClear' =&gt; true
                    ],
                    //'productname' =&gt; $productname,
                    ]);
                ?&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-3 col-sm-3 col-lg-3"&gt;
                &lt;?= DatePicker::widget([
                    'name' =&gt; 'Start Date',
                    'attribute' =&gt; 'from_date',
                    'value' =&gt; '2014-01-31',
                    'template' =&gt; '{addon}{input}',
                        'clientOptions' =&gt; [
                            'autoclose' =&gt; true,
                            'format' =&gt; 'yyyy-mm-dd'
                        ]
                ]);?&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-3 col-sm-3 col-lg-3"&gt;
                &lt;?= DatePicker::widget([
                    'name' =&gt; 'End Date',
                    'attribute' =&gt; 'to_date',
                    'value' =&gt; '2014-01-31',
                    'template' =&gt; '{addon}{input}',
                        'clientOptions' =&gt; [
                            'autoclose' =&gt; true,
                            'format' =&gt; 'yyyy-mm-dd'
                        ]
                ]);?&gt;
            &lt;/div&gt;
            &lt;div class="col-xs-1 col-sm-1 col-lg-1" &gt;

                &lt;?= Html::a('Search', ['/sbbtdtproduct/production/index','productname' =&gt; $model['productnames_productname']], ['class'=&gt;'btn btn-primary']) ?&gt;
            &lt;/div&gt;           
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>production controller action</p>

<pre><code>public function actionIndex($productname)
    {
        $productname = yii::$app-&gt;request-&gt;get('productnames_productname');
        $searchModel = new ProductionSearch();
        $dataProvider = $searchModel-&gt;search(Yii::$app-&gt;request-&gt;queryParams, $productname);

        return $this-&gt;render('index', [
            'searchModel' =&gt; $searchModel,
            'dataProvider' =&gt; $dataProvider,
        ]);
    }
</code></pre>

<p>productionsearch model</p>

<pre><code>public function search($params,$productname)
    {
        $query = Production::find()
                -&gt;where(['productname' =&gt; $productname]);

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' =&gt; $query,
        ]);

        $this-&gt;load($params);

        if (!$this-&gt;validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query-&gt;where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query-&gt;andFilterWhere([
            'productionid' =&gt; $this-&gt;productionid,
            'productiondate' =&gt; $this-&gt;productiondate,
            'itemid' =&gt; $this-&gt;itemid,
            'prodqty' =&gt; $this-&gt;prodqty,
        ]);

        $query-&gt;andFilterWhere(['like', 'productname', $this-&gt;productname])
            -&gt;andFilterWhere(['like', 'batchno', $this-&gt;batchno]);

        return $dataProvider;
    }
</code></pre>

<p>error - 
<a href="https://i.stack.imgur.com/Tz6ga.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Tz6ga.jpg" alt="enter image description here"></a>
<strong>update -</strong> 
<a href="https://i.stack.imgur.com/0hrEf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0hrEf.jpg" alt="enter image description here"></a>
<strong>Database Log</strong>
<a href="https://i.stack.imgur.com/ozBQO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ozBQO.jpg" alt="enter image description here"></a>
The data base Log shows that no value has been passed from search model.</p>

<p>I can see the value selected in select2 or datepicker as below, but it's not passing to the controller.</p>

<p><a href="https://i.stack.imgur.com/FTkfq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FTkfq.jpg" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/Dnyzb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dnyzb.jpg" alt="enter image description here"></a></p>