W
W
wolf-98302018-07-15 21:23:52
Yii
wolf-9830, 2018-07-15 21:23:52

Why is the form generating so many requests?

Created a form using ActiveForm and wrapped in pjax:

<?php Pjax::begin(['enablePushState' => false, 'timeout' => false, 'id' => 'addTaskPjax']) ?>
            <?php $form = ActiveForm::begin([
                'options' => [
                    'data-pjax' => '',
                    'id' => 'formAddTask',
                    'onSubmit' => 'formSubmit()' // удаляет кнопку "добавить"
                ]
            ]) ?>
            <div class="card-content white-text">
                <span class="card-title" style="font-size: 20px">Добавить задачу</span>
                <?= $form->field($model, 'name', [
                    'labelOptions' => [
                        'style' => 'font-size: 14px'
                    ]
                ])->textInput(
                    [
                        'style' => [
                            'color' => 'white'
                        ]
                    ]) ?>
                <?= $form->field($model, 'description', [
                    'labelOptions' => [
                        'style' => 'font-size: 14px'
                    ]
                ])->textarea([
                    'style' => [
                        'resize' => 'none',
                        'height' => '300px'
                    ]
                ]) ?>
                <label style="font-size: 14px; color: white">Привлечь работников</label><br>
                <?php foreach ($users as $user): ?>
                    <label>
                        <input type="checkbox" class="filled-in" name="workers[]" value="<?= $user->id ?>"/>
                        <span style="font-size: 14px; color: white; margin-left: 10px"><?= $user->last_name ?>
                            (<?= $user->login ?>)</span>
                    </label>
                <?php endforeach; ?>
                <div class="card-action">
                    <?= Html::submitButton('Добавить', [
                            'class' => 'waves-effect waves-light btn',
                            'id' => 'submitAddTask'
                    ]) ?>
                    <br>
                    <?php if ($message): ?>
                        <div class="card-panel red lighten-2"> <?= $message ?> </div>
                    <?php endif; ?>
                </div>

                <?php ActiveForm::end() ?>
            </div>

            <?php Pjax::end() ?>

But when submitting the form, an indefinite number of requests are generated somehow (sometimes 6, sometimes 3, sometimes 1), how can this happen?
5b4b90dc300f1922886947.png
Yes, in the screenshot these requests are without code 200, but somehow I create records in the database according to the number of these requests, the controller simply writes data from the form to the database and that's it. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-07-16
@kimono

Perhaps you have a loop in this place:

'onSubmit' => 'formSubmit()' // удаляет кнопку "добавить"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question