0

我在弹出登录表单中使用 zend 和 fancybox,但效果很好,问题出在我登录时。它重新加载fancybox,而不是当前的父页面。因此,当我登录时,它实际上在显示用户页面的登录表单框中。所以,我希望在提交时按下它与父页面而不是花式框一起记录。

这是我的代码:

javascript花式框:

$('a.iframe').fancybox({
        width   : 520, 
        height  : 300,
        type    : 'iframe',
        scrolling: 'no',
        centerOnScroll: 'true',
        onComplete: function() {
            $('#fancybox-frame').load(function() {
                $('#fancybox-content').height($(this).contents().find('body').height() + 0);
            });
        }
});

Zend 控制器:

public function loginFormAction()
{
    $this->_helper->layout()->disableLayout();
    //$this->_helper->viewRenderer->setNoRender(true);

    $email = $this->getRequest()->getParam('email');
    $password = $this->getRequest()->getParam('password');

    $loginForm = new Application_Form_UserLogin();
    if ($this->getRequest()->isPost())
    {
        /************ Login Form ************/
        if ($loginForm->isValid($this->getRequest()->getParams()))
        {
            $user = $this->_helper->model('Users')->createRow($loginForm->getValues()); 
            $user = $this->_helper->model('Users')->fetchRowByFields(array('email' => $email, 'hash' => $password));

            if($user) 
            {
                Zend_Session::rememberMe(86400 * 14);
                Zend_Auth::getInstance()->getStorage()->write($user);
                $this->getHelper('redirector')->gotoRoute(array(), 'invite');
                return;
            } 
            else {
                // Error message
                $this->view->errorMsg = "<b>password</b> - invalid, please try again! *";
            }               
        }
        else
        {
            // something
        }
    }
    $this->view->loginForm = $loginForm;
}

html表单:

<body>  
    <div id="login" class="">
        <div id="login_lb_content">
            <h1 class="content_title colorset_orange">Login to your account</h1>
            <form action="" method="post" name="loginForm" id="login-form">
                <table><tr>
                    <td colspan="2" class="content_sub_title colorset_gray">Your email address</td>
                </tr><tr>
                    <td colspan="2"><input id="email" type="text" name="email" value="<?php echo $this->loginForm->email->getValue(); ?>" /></td>
                </tr><tr>
                    <td width="120" class="content_sub_title colorset_gray">Your password</td>
                    <td style="text-align:right;" class="colorset_gray small_font">(It was sent to your email address when you registered)</td>
                </tr><tr>
                    <td colspan="2"><input id="password" type="password" name="password" value="<?php echo $this->loginForm->password->getValue(); ?>" /></td>
                </tr><tr>                       
                    <td><a id="inline-retreive" href="#retreive" class="content_sub_title colorset_orange fblink">Retreive my password</a></td>
                    <td><input type="submit" id="btn_login" name="login" value="" /></td>
                </tr></table>

                <div id="login-error" style="color:red">
                <?php if ($this->loginForm->getErrors()): ?>
                    <?php foreach($this->loginForm->getMessages() as $field => $messages): ?>
                        <strong><?php echo $field; ?></strong>
                        <?php foreach($messages as $messageKey => $message): ?>
                            - <?php echo $message; ?><br />
                        <?php endforeach; ?>
                    <?php endforeach; ?>
                <?php endif; ?>
                <?php echo $this->errorMsg; ?><br />
                </div>

            </form>
        </div>
    </div><!-- END div[login panel] -->

4

1 回答 1

0

实际上,它确实可以正常工作。它在fancybox 内刷新,因为它是一个iframe,它就像将表单嵌入到iframe标签中一样(只有iframe 将被重新加载,而不是父页面)

parent.$.fancybox.close();成功提交后,您需要使用表单中调用的方法....或者您可以onsubmit在表单标签中使用:

<form onsubmit="parent.$.fancybox.close();" ... 

...然后,在您的自定义脚本中添加选项:

"onClosed": function(){
  parent.location.reload(true);
}

刷新父页面。

注意:我假设您使用的是 fancybox v1.3.4,因为上面代码中的 API 选项。

于 2012-12-06T21:33:19.923 回答