-- iceangel89 <[email protected]> wrote
(on Sunday, 03 May 2009, 04:13 AM -0700):
> hmm i just wrote a custom validator ...
> 
> followng
> file:///D:/_FRAMEWORKS_/_ZF_TRUNK/documentation/manual/en/html/zend.validate.writing_validators.html
> 
> but even if i do just 
> 
> const ERROR = 'error';
> 
> protected $_messageTemplates = array(
>         self::ERROR => "%value% must be less than what has been issued"
> );
> 
> public function isValid($value, $context = null) {
>         $this->_error(self::ERROR);
>         return false;
> } 
> 
> it does not show any error messages?

Are you using this with Zend_Form? If so, was the element to which the
validator was attached marked required?

I took the above and did the following:

    class CustomValidator extends Zend_Validate_Abstract
    {
        const ERROR = 'error';

        protected $_messageTemplates = array(
                self::ERROR => "%value% must be less than what has been issued"
        );

        public function isValid($value, $context = null)
        {
                $this->_error(self::ERROR);
                return false;
        }
    }

    $v = new CustomValidator();
    if ($v->isValid('foo')) {
        echo 'should not validate!';
    } else {
        echo "Failed validation.\n";
        echo var_export($v->getMessages(), 1), "\n";
    }

And got the the correct output:

    Failed validation.
    array (
        'error' => ' must be less than what has been issued',
    )

so most likely the calling code is not actually calling the validator.

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to