Yii2 framework Multi input in the same form

Asked

Viewed 413 times

0

I’m using the widget https://github.com/unclead/yii2-multiple-input along with yii2 and I’m having an error at commit time.

My scenario is this: In my "catalogs" form the user can when creating the catalogue, create how many catalog items he wants to. That is, use in the catalog creation form the multi input widget to create various type records catalog items

I’m having the following mistake:

detalhe do erro

Code of my form:

<?= $form->field($model, 'mensagem2')->textInput(['maxlength' => true]) ?>


 <?php
        $models = Ponto_venda::find()->asArray()->all();
        $map = ArrayHelper::map($models, 'id_ponto_v', function($model, $defaultValue) {return $model['nome'].' - ' .$model['descricao'];}); 

 ?>
    <div class="row">
        <div class="col-lg-11">
            <?= $form->field($model, 'ponto_venda_id_ponto_v')->dropDownList($map) ?>
        </div>
        <div class="col-lg-1">
             <a class="btn btn-primary" href="index.php?r=ponto_venda%2Fcreate" role="button" style="margin-top:25px;"><span class="glyphicon glyphicon-plus"></span></a>
        </div>
    </div>
    <!-- Parte dos itens do catalogo -->
    <?php
        $item_models = Cerveja::find()->asArray()->all();
        $item_map = ArrayHelper::map($item_models, 'id_cerveja', function($item, $defaultValue) {return $item['nome'].' - '.$item['marca_id_marca'];}); 
    ?>      
    <br/>
    <?= $form->field($item, 'Item_catalogo')->widget(MultipleInput::className(), [
        'max' => 4,
        'columns' => [
            [
                'name'  => 'cerveja_id_cerveja',
                'type'  => 'dropDownList',
                'title' => 'Cerveja',
                'items' =>$item_map
            ],

            [
                'name'  => 'preco1',
                'enableError' => true,
                'title' => 'Preço1',
            ],
            [
                'name'  => 'preco2',
                'enableError' => true,
                'title' => 'Preço2',
            ],
            [
                'name'  => 'preco3',
                'enableError' => true,
                'title' => 'Preço3',
            ],
        ]
     ]);
    ?>
    <!-- -->

I can not understand why the error to the commit of catalog items being that in the POST apparently everything respects the rules of integrity... I’m new to the framework... Thank you!

1 answer

1


Try to add

<input id="form-token" type="hidden" name="<?=Yii::$app->request->csrfParam?>" value="<?=Yii::$app->request->csrfToken?>"/>

within the $form tag.

  • Thanks for answering, friend, but I ended up using this other widget https://github.com/wbraganca/yii2-dynamicform

  • The important thing is you solved it. Hugs!

  • @Brunocarazato , I’m glad you solved it, but the problem there is not with wdget but with a foreign key in your database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.