【问题标题】:Open bootstrap modal after failed submit提交失败后打开引导模式
【发布时间】:2017-01-05 16:43:53
【问题描述】:

我有一个模态的登录/注册表单。在提交失败并重新加载页面后,我想再次打开表单并在登录模式下方添加第二个模式。

我的代码不起作用:

if ($this->getRequest()->isPost())
    {
        $form->setData($this->getRequest()->getPost());
        /** @var \Zend\Authentication\Adapter\DbTable $Adapter */
        if ($form->isValid())
        {
            $data    = $form->getData();
            $Adapter = $this->authService->getAdapter();
            $Adapter
                ->setIdentity($data['email'])
                ->setCredential($data['password']);
            $authResult = $this->authService->authenticate();

            if (!$authResult->isValid())
            {
                echo "<script>
                $(document).ready(function(){
                  alert('hi');
                });
                    </script >";
            }

            else
            {
                return $this->redirect()->toRoute("blog");
            }
        }

        else
        {
            return new ViewModel(
                [
                    'form' => $form,
                ]
            );
        }
    }

【问题讨论】:

  • 由于您没有显示太多代码,您能否在您的&lt;script&gt; 标签之后插入alert('hi');?无效登录后是否会在页面重新加载时提醒您?
  • @lippoliv 警报不起作用
  • 所以你知道:你的 PHP 不会渲染脚本。愿您向我们展示更多您的 PHP 代码,以便我们为您提供帮助。
  • @lippoliv 我添加了更多代码,但我不确定这是否会对您有所帮助
  • 您的代码肯定不可读。在 laravel 路由中,您不必检查帖子。只需添加一个 POST-Routing,没有 GET-Routing 和 laravel 会为你做检查。您能否将您的echo 替换为dd 调用以查看您的PHP 是否到达该代码行?

标签: jquery twitter-bootstrap bootstrap-modal


【解决方案1】:

当您将 (return $this-&gt;redirect()-&gt;toRoute("blog");) 重定向到另一条路线时,您的“回声”不会呈现。新路由的新 HTML 将呈现。

所以你的回声必须在新路由中(可能通过参数)

【讨论】:

    猜你喜欢
    • 2014-08-29
    • 2016-07-03
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    相关资源
    最近更新 更多