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

Was it helpful?

Solution

Use getMessages() and check if variable is empty.

foreach ($form as $element) {
    $messages = $element->getMessages();

    if (!empty($messages)) {
        // do something
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top