Use getMessages() and check if variable is empty.
foreach ($form as $element) {
$messages = $element->getMessages();
if (!empty($messages)) {
// do something
}
}
Question
When i submit a form of Zend Framework 2, i would like to check in each single input has any errors, and if so, do something in the view.
Is there any "hasError()" (of the single input element) method? For the Form, there is the "isValid()" method.
Thanks
Solution
Use getMessages() and check if variable is empty.
foreach ($form as $element) {
$messages = $element->getMessages();
if (!empty($messages)) {
// do something
}
}