开发者

ZF Form refuses to POST

开发者 https://www.devze.com 2023-01-12 19:36 出处:网络
I\'m perplexed by this. I have a login action that looks like this: public function loginAction() { $form = new Application_Form_Login;

I'm perplexed by this. I have a login action that looks like this:

public function loginAction()
{
    $form = new Application_Form_Login;
    $form->setAction("/users/login");

    $request = $this->getRequest();

    var_dump($request->isPost());
    if ($request->isPost() && $form->isValid($request->getPost())) {
        // snipped code that is never reached anyway
    }

    $this->view->form = $form;
}

And a form:

class Application_Form_Login extends Zend_Form
{
    public function init()
    {
        $this->setMethod("post");

        $email = new Zend_Form_Element_Text("email");
        $email->addFilter("StringTrim")
              ->addValidator("NotEmpty")
              ->addValidator("EmailAddress")
              ->setRequired(true)
              ->setLabel("Email address");
        $this->addElement($email);

        $password = new Zend_Form_Element_Password("password");
        $password->addFilter("StringTrim")
                 ->addValidator("NotEmpty")
                 ->setRequired(true)
                 ->setLabel("Password");
        $this->addElement($password);

        $submit = new Zend_Form_Element_Submit("finish");
        $submit->setLabel("Login");
        $this->addElement($submit);
    }
}

var_d开发者_如何学Pythonump($request->isPost()) always returns false, yet in a mostly identical action it works perfectly! Any ideas?


I tracked it down. I had a redirect on /users to redirect back to /users/login if the user was not logged in. I wasn't saving the result of Zend_Auth in storage, thus giving me the impression login was doing nothing.

POST http://localhost/users/login (302 Found)
GET http://localhost/users
GET http://localhost/users/login
0

精彩评论

暂无评论...
验证码 换一张
取 消