Oscar Fanelli
Oscar Fanelli

Reputation: 3677

Check any errors in Zend Form text input

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

Upvotes: 1

Views: 755

Answers (1)

Adrian Nowicki
Adrian Nowicki

Reputation: 703

Use getMessages() and check if variable is empty.

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

    if (!empty($messages)) {
        // do something
    }
}

Upvotes: 2

Related Questions