开发者

Force error message to Zend Form Element

    // Process the forms
    if (($this->getRequest()->is开发者_如何学PythonPost())
            && ($this->getRequest()->isXmlHttpRequest())) {

        // Initiate response
        $status = false;
        $msg = '';
        $zf = null;

        // Error test
        $form->getElement('no')->addError('This is the error message');            

        if ($form->isValid($this->getRequest()->getPost())) {

        // Everything is good
            $status = true;

        } else {

        // Get the error messages
            $zf = $form->getMessages();
        }

        // Setup the response
        $result = json_encode(array('status' => $status,
                                    'msg' => $msg,
                                    'zf' => $zf));

        $this->_helper->viewRenderer->setNoRender();
        $this->_helper->layout()->disableLayout();

        $this->getResponse()->setHeader('Content-Type', 'application/json');
        $this->getResponse()->setBody($result);

        return;

    } else {
        // Populate the form
    }

As you can see, I've used $form->getElement('no')->addError('This is the error message'); to force error on the form element, but $form->getMessages(); would still return NULL. So, what should I do to force error on the selected form element?


I think you've got the get the ErrorMessages()

$form->getErrorMessages()


I've opened a bug report for this issue: http://framework.zend.com/issues/browse/ZF-11088. I'll update this question if there's any new progress.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜