V
V
Victor Umansky2017-08-18 00:12:06
Yii
Victor Umansky, 2017-08-18 00:12:06

How to use two forms with one button?

Good night everyone, I have such a question, the screenshot shows that TABAS are used. In the first tab there is a form, after filling out, we click on the continue button and it throws us, on the second tab there is also a form and after the selected fields there is an order button.
I can't figure out how to correctly place the forms for submitting data in tabs, I use yii2 bootstrap/tab
. And help me get it right!

<?= Tabs::widget([
        'items' => [
            [
                'label' => 'Контактные данные',
                'options' => ['id' => 'activeAccount'],
                'visible' => Yii::$app->user->id,
                'content' => $this->render('_tabs/activeAccount', [
                    'order' => $order,
                    'user' => $user,
                    'userCabinet' => $userCabinet,
                ]),
            ],
            [
                'label' => 'Доставка оплата',
                'options' => ['id' => 'deliveryPayment'],
                'content' => $this->render('_tabs/deliveryPayment', [
                    'model' => $model,
                ]),
            ],
        ]
    ]);
    ?>

777fd16e80.png
de14d0a316.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-08-18
@Uman

You wrap all the tabs in one form, you can pass the tab to the render $form. The submit button in the last and FSE.

M
matperez, 2017-08-18
@matperez

I won’t tell you directly in detail, but the general procedure can be as follows:
On the first tab, intercept the submit and switch to the second tab. You can read how to intercept the submit here https://yii2-cookbook.readthedocs.io/forms-activef... How to switch to the second tab in js, google it yourself.
On the second tab, you can repeat this focus and, as a result, send the data of both forms via ajax request to the backend.
Here the right question is not how to do it in principle, but where to store the state between the steps of the form (how to get the data of the previous one at the next step). You can store it on the backend in the session, you can store it in GET parameters, you can store it directly in html (as mentioned above), or you can store it in some separate js object. Decide what is more convenient for you and then it will be clear how exactly to implement it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question