1

ユーザー名、パスワード、検証付きの送信の3つの入力を含むログインフォームがあります。ユーザー名またはパスワードのいずれかが空の場合、検証は正しく失敗します。ただし、Chromeではフォームを再送信できません。[送信]をクリックしても効果はありません。IEとFirefoxでは正常に動作します。

Zend Controller Action:

public function loginAction()
    {
        $this->_helper->layout->setLayout('layout_nomenu');
        $loginForm = new Application_Form_Login();

        $request = $this->getRequest();
        if ($request->isPost()) {

            if ($loginForm->isValid($request->getPost())) {

                $valid = false;
                if ($valid) {
                //if ($this->_process($loginForm->getValues())) {
                    $this->_helper->redirector('users', 'grid');
                } else {
                    $this->view->loginfail = "Login details not recognised, please try again";
                } 
            } 
        }
        $this->view->login = $loginForm;
    }

forms.ini:

[login]
action = "login"
method = "post"
name = "login"

elements.username.type = "text"
elements.username.options.label = "Username:"
elements.username.options.validators.strlen.validator = "StringLength"
elements.username.options.validators.strlen.options.min = "2"
elements.username.options.validators.strlen.breakChainOnFailure = "true"
elements.username.options.required = "true"

elements.password.type = "password"
elements.password.options.label = "Password:"
elements.password.options.validators.strlen.validator = "StringLength"
elements.password.options.validators.strlen.options.min = "2"
elements.password.options.validators.strlen.breakChainOnFailure = "true"
elements.password.options.required = "true"

elements.submit.type = "submit"
elements.submit.options.label = "Login"

displayGroups.loginform.elements.username   =   "username"
displayGroups.loginform.elements.password   =   "password"
displayGroups.loginform.elements.submit     =   "submit"
displayGroups.loginform.options.legend      =   "Login"

Login form:

class Application_Form_Login extends Zend_Form
{
    public function init()
    {

        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/forms.ini', 'login');
        $this->setOptions($config->toArray());
        //$this->addElement('hash', 'no_csrf_foo', array('salt' => 'unique'));

    }
}

htmlは非常に単純です-jsなどはありません:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Development </title>



<link href="/css/global.css" media="screen" rel="stylesheet" type="text/css" /><link href="/css/global.css" media="screen" rel="stylesheet" type="text/css" />

<link href="/css/development.css" media="screen" rel="stylesheet" type="text/css" />

</head>

<body>

    <div id="header">

        <div id="header-logo" style="float: left"><img src="/images/small.gif" alt="Development" style="margin-top:5px" />&nbsp;&nbsp;Development</div>

        <div id="header-navigation" style="float: right">

        </div>

    </div>



    <div id="view-content">
<div id="loginform">
<form id="login" enctype="application/x-www-form-urlencoded" action="login" method="post"><dl class="zend_form">

<dt id="loginform-label">&#160;</dt><dd id="loginform-element"><fieldset id="fieldset-loginform"><legend>Login</legend>

<dl>

<dt id="username-label"><label for="username" class="optional">Username:</label></dt>

<dd id="username-element">

<input type="text" name="username" id="username" value="a" />

<ul class="errors"><li>'a' is less than 2 characters long</li></ul></dd>

<dt id="password-label"><label for="password" class="optional">Password:</label></dt>

<dd id="password-element">

<input type="password" name="password" id="password" value="" /></dd>

<dt id="submit-label">&#160;</dt><dd id="submit-element">

<input type="submit" name="submit" id="submit" value="Login" /></dd></dl></fieldset></dd></dl></form>   <div id="loginerror">
        </div>
</div>
<div id="loginspacer">&nbsp;</div>
</div>


<div id="footer">

<div id="footer-logo"></div>

<div id="footer-navigation">Quetzal Technology 2012</div>

</div>

</body>

</html>
4

1 に答える 1

0

もう少し簡単に試してみて、何が起こるか見てみましょう:

public function loginAction()
    {
        $this->_helper->layout->setLayout('layout_nomenu');
        $loginForm = new Application_Form_Login();

        $request = $this->getRequest();
        if ($request->isPost()) {

            if ($loginForm->isValid($request->getPost())) {

                    $this->_helper->redirector('users', 'grid'); //go here if valid                   
            } else {
            //go here if not valid
            $this->view->loginfail = "Login details not recognised, please try again";

            }          

        } 
        //if  not post show form
        $this->view->login = $loginForm;
    }

場合によっては、その余分なループが問題を引き起こしているのではないかと考えなければなりません。

于 2012-08-02T11:53:45.230 に答える