Set Zend\\Form Error Messages from Controller

自作多情 提交于 2019-12-05 07:43:25

My comment as answer, as you've requested:

You can also set error messages to an element directly, using:

$form->get('elemName')->setMessages(array('message1', 'message2', ...));

Simple solution, read the code correctly... Correct usage as following:

$form->setMessages(array(
    'formElementName' => array(
         // multiple error messages possible...
    )
));

Use this lines of code.

$form->getElement('controlname')->setErrors(array('Your custom error'));

in case the message not showing in your page check removeDecorator method used in zend form. if there is use addDecorator method befor writing error message code line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!