H
H
hollanditkzn2017-05-18 14:50:18
Yii
hollanditkzn, 2017-05-18 14:50:18

How did pjax reset the form when submitting the form?

pjax is used Inside pjax, a form is sent and a flash message is displayed. It turns out that when the form is sent, the input is not reset and exits when the page is refreshed again, a new line is added to the database. In the controller I wrote

if($reminder->load(Yii::$app->request->post())){
            $reminder->getReminder($zakaz);
            if($reminder->validate() && $reminder->save()){
                Yii::$app->session->setFlash('success', 'Напоминание было созана');
            } else {
                Yii::$app->session->setFlash('error', 'Извините. Напоминание не было создана');
            }
            return $this->redirect(['view', 'id' => $model->id_zakaz]);
        }

in view
<?php $formReminder = ActiveForm::begin(); ?>
            
            <?= $formReminder->field($reminder, 'srok')->textInput(['type' => 'datetime-local', 'required' => 'required']) ?>
            
            <?= Html::submitButton('Напомнить', ['class' => 'btn btn-primary btn-sm']) ?>
            
            <?php ActiveForm::end(); ?>

I wanted to use without redirect

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2017-05-18
@webinar

Why is pjax in pjax? And what's with the code you gave? He has nothing to do with it. And how do you plan to combine pjax and $this->redirect? Pjax makes a request and needs to get $this->render to do its job and replace the content. And you do not give him content.

M
Maxim Fedorov, 2017-05-18
@qonand

Clear the data from the class stored in the $reminder variable after saving

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question