Answer the question
In order to leave comments, you need to log in
Why do Yii2 js elements disappear after submitting a form?
Good day! There is a form that is submitted asynchronously using pjax. After sending, js does not fully work, and to be more precise, exactly two scripts that I noticed do not work. Here is the controller file:
public function actionIndex() {
$model = new SimpleMails();
if ( $model->load( Yii::$app->request->post() ) && $model->validate() ) {
$model->save();
if ( ! Yii::$app->request->isPjax ) {
Yii::$app->session->setFlash( 'form_sended', '<h2 class="uppercase">Thank You!</h2><p>We will get back to you as soon as possible</p>' );
return $this->redirect( [ 'index#thank-you' ] );
} else {
}
Yii::$app->session->setFlash( 'form_sended', '<h2 class="uppercase">Thank You!</h2><p>We will get back to you as soon as possible</p>' );
$model = new SimpleMails();
}
return $this->render( 'index', compact('model') );
}
Answer the question
In order to leave comments, you need to log in
After the pjax update, you need to re-initialize the script that you need.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question