简体   繁体   中英

Open bootstrap modal after failed submit

I got a login/register form in a modal. And after the submit failed and the page reloaded, I want to open the form again and add a second modal below the login modal.

My code doesn't work:

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,
                ]
            );
        }
    }

As of you're doing an redirect ( return $this->redirect()->toRoute("blog"); ) to another route, your "echo" doesn't render. The new HTML of new Route will render.

So your echo has to be in the new route (may via an Parameter)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM