PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Limit the size of a validation message

Sometimes it is necessary to limit the maximum size a validation message can have. For example when your view allows a maximum size of 100 chars to be rendered on one line. To simplify the usage, Zend_Validate is able to automatically limit the maximum returned size of a validation message.

To get the actual set size use Zend_Validate::getMessageLength(). If it is -1, then the returned message will not be truncated. This is default behaviour.

To limit the returned message size use Zend_Validate::setMessageLength(). Set it to any integer size you need. When the returned message exceeds the set size, then the message will be truncated and the string '...' will be added instead of the rest of the message.

<?php
Zend_Validate
::setMessageLength(100);

Where is this parameter used?

The set message length is used for all validators, even for self defined ones, as long as they extend Zend_Validate_Abstract.

Zend Framework