0

I have bootstarp tabs in yii2 view page Each tab have different model's active form. Client side was working fine on all the forms. But form submission on the forms is not working. Only one form is working fine. others are not submitting the form.

    <ul class="nav nav-tabs" id="myTab">
        <li class="active"><a class="active" data-toggle="tab" data-target="#customers"><span>Customer</span></a></li>
        <li><a data-toggle="tab" data-target="#drivers"><span>Drivers</span></a></li>
        <li><a  data-toggle="tab" data-target="#agents"><span>Agents</span></a></li>        
    </ul>

    <div class="tab-content">        
        <div id="customers" class="tab-pane" style="display:none">
        <?php $form = ActiveForm::begin(['action' => Url::to(['/account/customer_transaction'])]); ?>
                <?= $form->field($transaction, 'customer_selection_type')->radioList([1 => Yii::t('backend', 'ALL_CUSTOMERS'), 2 => Yii::t('backend', 'SELECT_CUSTOMER')]) ?>
                <?= $form->field($transaction, 'customer')->dropDownList(ArrayHelper::map($customers, 'u_user_id', 'u_full_name'), ['class' => 'selectpicker', 'multiple' => true]) ?>
                <?= $form->field($transaction, 'transaction_type')->radioList([1 => Yii::t('backend', 'CREDIT'), 2 => Yii::t('backend', 'DEBIT')]) ?>
                <?= $form->field($transaction, 'transaction_amount')->textInput() ?>
                <?= $form->field($transaction, 'remarks')->textArea(['rows' => 4]) ?>
                <?= Html::submitButton(Yii::t('backend', 'SUBMIT'), ['class' => 'btn btn-success'])?>
            <?php ActiveForm::end(); ?>  

            <h2>Transaction</h2>
            <div class="transactiondetail-index">
                <?php Pjax::begin(); ?>    <?= GridView::widget([
                        'dataProvider' => $customerDataProvider,
                        'filterModel' => $customerSearchModel,
                        'columns' => [
                            ['class' => 'yii\grid\SerialColumn'],
                            [
                                'attribute' => 'td_created_datetime',
                                'format' => ['date', 'dd-M-Y, HH:i:ss'],
                                'filter' => false,
                            ],
                            [
                                'attribute' => 'user.u_full_name',
                                'filter' => Html::activeDropDownList($customerSearchModel, 'td_user_id', ArrayHelper::map($customers, 'u_user_id', 'u_full_name'), ['prompt' => Yii::t('backend', 'SELECT_CUSTOMER')])
                            ],
                            [
                                'attribute' => 'td_transaction_type',
                                'value' => function($model){
                                    if($model->td_transaction_type == 1)
                                        return Yii::t('backend', 'REFERRAL');
                                    else if($model->td_transaction_type == 2)
                                        return Yii::t('backend', 'PROMO');
                                    else if($model->td_transaction_type == 3)
                                        return Yii::t('backend', 'Gateway');
                                    else if($model->td_transaction_type == 4)
                                        return Yii::t('backend', 'TRIP');
                                    else if($model->td_transaction_type == 5)
                                        return Yii::t('backend', 'CREDIT');
                                    else if($model->td_transaction_type == 6)
                                        return Yii::t('backend', 'DEBIT');
                                },
                                'filter' => Html::activeDropDownList($customerSearchModel, 'td_transaction_type', [1 => Yii::t('backend', 'REFERRAL'), 2 => Yii::t('backend', 'PROMO'), 5 => Yii::t('backend', 'CREDIT'), 6 => Yii::t('backend', 'DEBIT')], ['prompt' => Yii::t('backend', 'SELECT_TRANSACTION_TYPE')])
                            ],
                            'td_amount',
                            'td_previous_wallet_balance',
                            'td_current_wallet_balance',
                            [
                                'class' => 'yii\grid\ActionColumn',
                                'template' => '{view}',
                                'buttons' => [
                                    'view' => function($url, $model, $id){
                                        return  Html::a('<span class="glyphicon glyphicon-eye-open"></span>', ['account/view_customer_transaction', 'id' => $model->td_user_id] , ['target' => '_blank']); 
                                    }
                                ],
                            ],

                        ],
                    ]); ?>
                <?php Pjax::end(); ?>
            </div>
        </div>
        <div id="drivers" class="tab-pane" >
            <div class="driver_form">
            <?php $driverForm = ActiveForm::begin(['action' => Url::to(['/account/driver_transaction']), 'options' => ['id' => 'driver_form']]); ?>
                <?= $driverForm->field($driverModel, 'country')->dropDownList(ArrayHelper::map($countries, 'co_id', 'co_name'), ['prompt' => Yii::t('backend', 'SELECT_COUNTRY')]) ?>
                <?= $driverForm->field($driverModel, 'city')->dropDownList([], ['prompt' => Yii::t('backend', 'SELECT_CITY')]) ?>
                <?= $driverForm->field($driverModel, 'driver_selection_type')->radioList([1 => Yii::t('backend', 'ALL_DRIVERS'), 2 => Yii::t('backend', 'SELECT_DRIVER')]) ?>
                <?= $driverForm->field($driverModel, 'driver_id')->dropDownList([], ['class' => 'selectpicker', 'multiple' => true]) ?>
                <?= $driverForm->field($driverModel, 'transaction_type')->radioList([1 => Yii::t('backend', 'CREDIT'), 2 => Yii::t('backend', 'DEBIT')]) ?>
                <?= $driverForm->field($driverModel, 'transaction_amount')->textInput() ?>
                <?= $driverForm->field($driverModel, 'remarks')->textArea(['rows' => 4]) ?>
                <?= Html::submitButton(Yii::t('backend', 'SUBMIT'), ['class' => 'btn btn-success'])?>
            <?php ActiveForm::end(); ?>
            </div>
        </div>
    </div>  

If anyone knows about it kindly help me

Sivabalan
  • 971
  • 2
  • 18
  • 43
  • 1
    Does the same happen when you remove Pjax? – Bizley Oct 06 '16 at 15:00
  • I removed the pjax but still its not working – Sivabalan Oct 07 '16 at 04:13
  • The form should post. Maybe one of the fields fails validation but the validation is not shown for some reason. Have you tried commenting out all of the fields but one and check if the post works. If so, add the next field and do the same and so on... – Barry Oct 07 '16 at 09:55

2 Answers2

0

Forms need unique ids. Try like this:

<?php 
$form = ActiveForm::begin([
   'id' => 'id1'
   'action' => Url::to(['/account/customer_transaction'
])]); 
?>
Ciprian
  • 3,066
  • 9
  • 62
  • 98
0

Set enableCsrfValidation to false in controller

class CmsController extends Controller
{
    public $enableCsrfValidation = false;
    public $layout="listing";
    public function behaviors()
    {
       .........
    }
}
Arshad Shaikh
  • 564
  • 1
  • 3
  • 13