Get error while tying to get tabular input data

I’m getting error (Call to a member function formName() on a non-object) while trying to get data from tabular input. Here’s my code -

View Code:


$arr = array("config", "specs");

foreach($arr as $index=>$value){

    echo '<h3>' . $value . '</h3>';

    for($i=0; $i<3; $i++){

    echo '<div class="text-row">';

        echo $form->field($configmodel, "[$index]config[$i]")->label(false);

        echo '<p class="invisible"></p>';

    echo '</div>';

    }

}

Controller Code:


$model = new TestForm();

$configmodel = new ConfigForm();

    

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

    if(Model::loadMultiple($configmodel, Yii::$app->request->post()) &&  Model::validateMultiple($configmodel)){

        return $this->render('result', [

            'model' => $model,

            'configmodel' => $configmodel

        ]);

    }

    

} else {

    return $this->render('index', [

        'model' => $model,

        'configmodel' => $configmodel

    ]);

}

Model Code:


class ConfigForm extends Model

{

    public $config;


    public function rules()

    {

        return [

            ['config', 'required'],

            ['config', 'string' , 'min' => 20],

        ];

    }

}

It seems the problem would be in the field names. I just quickly looked into some of our apps and we have the names like this for tabular inputs of multiple models: "ModelName[$index][$field]"

I recommend you to debug your app and look what’s going on in yii\base\Model::loadMultiple().

You will see why the passed POST data don’t match with the data expected.