【问题标题】:Yii2 how to use pjax to submit a form without closing bootstrap modal popupYii2如何使用pjax提交表单而不关闭引导模式弹出窗口
【发布时间】:2017-11-29 12:16:05
【问题描述】:

我正在为登录页面使用引导模式。如果我在弹出窗口中提交表单将被关闭并显示响应。但不是关闭弹出窗口,而是想在同一个弹出窗口中显示响应。任何人都可以在不关闭弹出窗口以显示响应数据的情况下帮助我。

示例查看页面:

<?php Pjax::begin(); ?>
<?= Html::beginForm(['site/login'], 'post'); ?>
<?= Html::input('text', 'email', ['class' => 'form-control']) ?>
<?= Html::input('text', 'password', ['class' => 'form-control']) ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-lg btn-primary', 'name' => 'login']) ?>
<?= Html::endForm() ?>

在控制器中

if ($model->load(\Yii::$app->request->post())) {

     $authenticateUser = $model->login();
     if($authenticateUser == "Locked"){
        Yii::$app->session->setFlash('invalid', 'Your account has been locked. Please contact customer service for assistance');
                return $this->redirect('index');
     }else{
        Yii::$app->session->setFlash('success', 'Successfully logged in');
                 return $this->redirect('index');
     }
}

在控制器中,我也尝试使用 renderAjax 而不是 redirect 。但它没有按预期工作。

【问题讨论】:

    标签: php jquery twitter-bootstrap yii2 yii2-advanced-app


    【解决方案1】:

    您需要通过添加您自己的 javascript 处理程序 beforeSubmit 来强制通过 ajax 提交表单。见this link

    【讨论】:

      【解决方案2】:

      试试下面一个

      use yii\widgets\Pjax;
      use yii\bootstrap\ActiveForm;
      
      <?php Pjax::begin(); ?>
          <?php 
            $form = ActiveForm::begin([
              'id' => 'form-id',                   
              'options' => ['class' => 'form-horizontal','data-pjax' => true],
            ]);  
          ?>
              // Your fields
          <?php ActiveForm::end(); ?>
      <?php Pjax::end(); ?>
      

      【讨论】:

        猜你喜欢
        • 2015-10-06
        • 1970-01-01
        • 2013-09-24
        • 2012-01-26
        • 1970-01-01
        • 2012-08-14
        • 2014-05-30
        • 1970-01-01
        • 2018-05-08
        相关资源
        最近更新 更多