views:

18

answers:

1

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_dump($request->isPost()) always returns false, yet in a mostly identical action it works perfectly! Any ideas?

+1  A: 

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
Ross