Using Yii 2.0 i'm trying to grab some $\_POST values in my controller from my view but cannot do this. I will show you my code and talk you through it below.

**Models/CaseSearch.php**

```
 <?php

 namespace app\models;

 use Yii;
 use yii\base\Model;
 use yii\data\ActiveDataProvider;
 use app\models\Cases;

 /**
 * CaseSearch represents the model behind the search form about `app\models\Cases`.
 */

class CaseSearch extends Cases
{

public $category;
public $subcategory;
public $childcategory;
public $newcategory;
/**
 * @inheritdoc
 */
public function rules()
{
    return [
        [['case_id', 'year'], 'integer'],
        [['name', 'judgement_date', 'neutral_citation', 'all_ER', 'building_law_R', 'const_law_R', 'const_law_J', 'CILL', 'adj_LR'], 'safe'],
    ];
}

/**
 * @inheritdoc
 */
public function scenarios()
{
    // bypass scenarios() implementation in the parent class
    return Model::scenarios();
}

/**
 * Creates data provider instance with search query applied
 *
 * @param array $params
 *
 * @return ActiveDataProvider
 */
public function search($params)
{
    $query = Cases::find();

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

    $this->load($params);

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

    $query->andFilterWhere([

        'case_id' => $this->case_id,
        'judgement_date' => $this->judgement_date,
        'year' => $this->year,
    ]);

    $query->andFilterWhere(['like', 'name', $this->name])
        ->andFilterWhere(['like', 'neutral_citation', $this->neutral_citation])
        ->andFilterWhere(['like', 'all_ER', $this->all_ER])
        ->andFilterWhere(['like', 'building_law_R', $this->building_law_R])
        ->andFilterWhere(['like', 'const_law_R', $this->const_law_R])
        ->andFilterWhere(['like', 'const_law_J', $this->const_law_J])
        ->andFilterWhere(['like', 'CILL', $this->CILL])
        ->andFilterWhere(['like', 'adj_LR', $this->adj_LR]);

    return $dataProvider;
}

public function searchByCategory($category){
    $query = Cases::find();

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

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

    $query->andFilterWhere([

        'category_id' => $category

    ]);

    return $dataProvider;
}   
}

```

**Okay so now is my view:**

```
  <?php

    $form = ActiveForm::begin();

    echo $form->field($searchModel, 'category')
                ->dropDownList(
                    ArrayHelper::map($allCategory, 'id', 'name'),
                    [
                        'onchange'=>'getSubcategory()',
                    ]
    );

    //To stop errors, if first category not chosen make subcategory and empty drop down.
    $subcategory = array(
        "empty" => ""

    );

    echo $form->field($searchModel, 'subcategory')
                ->dropDownList(
                    ArrayHelper::map($subcategory, 'id', 'name'),
                    [
                       'onchange'=>'getChildcategory()',
                    ]
    );
    //To stop errors, if second category not chosen make childcategory and empty drop down.
    $childcategory = array(
        "empty" => ""
    );
    echo $form->field($searchModel, 'childcategory')
                ->dropDownList(
                    ArrayHelper::map($childcategory, 'id', 'name'),
                    [
                       //'onchange'=>'getChildCategory()',
                        'onchange'=>'submitNow()',
                    ]
    );

    echo '<div class="form-group">';
        echo Html::submitButton('Submit', ['class' => 'btn btn-primary']);
    echo '</div>';
    ActiveForm::end();

```

Ok, so when i click the submit button i want to capture the value in my controller so that i can use this to alter the results given in the gridview. 

When i inspect the element on the drop down lists the names are weird so i am not sure if this is making a different. for example the name for subcategory is actually: CaseSearch[subcategory]

**Now for my controller:**

```
public function actionIndex()
{
//
// This is for the first render of index
//
    $model = new Cases;
    $searchModel = new CaseSearch();  
    $allCategory = Category::find()->all();
    $dataProvider = $searchModel->search(Yii::$app->request->queryParams);       
    //
    // This is for when i click the submit button on the view. I want it to submit and then grab the subcategory in variable $subtest. I make $subtest = 1 so that when i first render the page it doesn't throw an error and when submitted it should change to the post value
    // 

    $subtest = 1;
    if($searchModel->load(Yii::$app->request->post())){
        $subtest = $_POST['subcategory'];

    }

    return $this->render('index', [
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider,
        'allCategory' => $allCategory,
        'model' => $model,  
        'subtest' => $subtest
    ]);
}

```

However when i try to print\_r() the variable $subtest in my view i get the error:

```
  Undefined index: CaseSearch[subcategory]

```

and its for the line:

```
  $subtest = $_POST['CaseSearch[subcategory]'];

```

In my controller.

Can anyone please advise as i cannot figure out why?