简体   繁体   English

强制将错误消息发送到Zend表单元素

[英]Force error message to Zend Form Element

    // Process the forms
    if (($this->getRequest()->isPost())
            && ($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'); 如您所见,我使用了$form->getElement('no')->addError('This is the error message'); to force error on the form element, but $form->getMessages(); 强制在表单元素上出错,但是$form->getMessages(); would still return NULL . 仍将返回NULL So, what should I do to force error on the selected form element? 那么,我该怎么做才能在选定的表单元素上强制错误?

我认为您已经获得了ErrorMessages()

$form->getErrorMessages()

I've opened a bug report for this issue: http://framework.zend.com/issues/browse/ZF-11088 . 我已针对此问题打开了错误报告: http : //framework.zend.com/issues/browse/ZF-11088 I'll update this question if there's any new progress. 如果有任何新进展,我将更新此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM