Php 如何在Zend Framework 1.12中的controller中检查表单验证

Php 如何在Zend Framework 1.12中的controller中检查表单验证,php,validation,zend-framework,zend-framework2,Php,Validation,Zend Framework,Zend Framework2,如何检查表单是否经过验证,以及如果表单未通过验证,如何显示错误消息 在zf2中,我们写为 userController $request = $this->getRequest(); $form = new Form_LoginForm(); if($request->isPost()){ if($form->isvalid($this->_request->getPost())){ $authAdapter = $this->get

如何检查表单是否经过验证,以及如果表单未通过验证,如何显示错误消息

在zf2中,我们写为

userController

$request = $this->getRequest();
$form = new Form_LoginForm();
if($request->isPost()){
    if($form->isvalid($this->_request->getPost())){
        $authAdapter = $this->getAuthAdapter();
        $username = 'john';
        $password = '123';
        $authAdapter->setIdentity($email)
                    ->setCredential($password);
        $auth = Zend_Auth::getInstance();
        $result = $auth->authenticate($authAdapter);
        if($result->isvalid()){
            $identity = $authAdapter->getResultRowObject();
            $authStorage = $auth->getStorage();
            $authStorage->write($identity);
            $this->_helper->redirector(register/user);
            echo 'valid';
        } else {
            $this->view->errorMessage = "User name or password is incorrect";
        }
    }
}
上面的代码在ZendFramework2中,我需要ZendFramework1.12中的代码。如何将表单从login.phtml获取到userController中,以及如何编写代码以检查验证,如zend framework2中编写的第4行所示

我的login.phtml表单是


像这样的怎么样

    $form           =   new Form_LoginForm();

if ($this->getRequest()->isPost()) 
{
    if ($form->isValid($_POST)) 
    {
        $formData       =   $this->_getFormData();
        $authAdapter    =   $this->_getAuthAdapter($formData);
        $auth           =   Zend_Auth::getInstance();
        $result         =   $auth->authenticate($authAdapter);

        /**
         * Authentication failed
         */
        if (!$result->isValid()) 
        {
            switch ($result->getCode())
            {
                // Username doesn't exist
                case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND   :   $yourLogic;
                                                                        break;
                // Username and Password combination was incorrect
                case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID   :   $yourLogic;
                                                                        break;
                // General error message
                default :   $yourLogic;
            }
        }
        /**
         * Authentication success
         */
        else 
        {
            // Store the identity as an object where the password column has been omitted
            $data   =   $authAdapter->getResultRowObject(null, 'password');
        }
    }
}

您可以在ZF1.12的文档中看到,除了Q之外,它非常有帮助@Dodd44为您感到高兴:祝你好运
    $form           =   new Form_LoginForm();

if ($this->getRequest()->isPost()) 
{
    if ($form->isValid($_POST)) 
    {
        $formData       =   $this->_getFormData();
        $authAdapter    =   $this->_getAuthAdapter($formData);
        $auth           =   Zend_Auth::getInstance();
        $result         =   $auth->authenticate($authAdapter);

        /**
         * Authentication failed
         */
        if (!$result->isValid()) 
        {
            switch ($result->getCode())
            {
                // Username doesn't exist
                case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND   :   $yourLogic;
                                                                        break;
                // Username and Password combination was incorrect
                case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID   :   $yourLogic;
                                                                        break;
                // General error message
                default :   $yourLogic;
            }
        }
        /**
         * Authentication success
         */
        else 
        {
            // Store the identity as an object where the password column has been omitted
            $data   =   $authAdapter->getResultRowObject(null, 'password');
        }
    }
}