you are right, the validator is not called. 

i added it in my Zend_Form class

$this->broken = new Zend_Form_Element_Text("broken");
$this->broken->addValidator(new Lab_Validator_LessThanBalance());

if i do a 

$v = new Lab_Validator_LessThanBalance();
$v->isValid("test");

it ran but i got 

Exception information:

Message: No property exists by the name '0'
Stack trace:

#0 D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Validate\Abstract.php(230):
Zend_Validate_Abstract->__get('0')
#1 D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Validate\Abstract.php(250):
Zend_Validate_Abstract->_createMessage('error', NULL)
#2
D:\Projects\zf-ims\application\modules\lab\validators\LessThanBalance.php(18):
Zend_Validate_Abstract->_error('error')
#3
D:\Projects\zf-ims\application\modules\lab\controllers\TransactionsController.php(50):
Lab_Validator_LessThanBalance->isValid('test')
#4 D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Controller\Action.php(512):
Lab_TransactionsController->addrecordAction()
#5
D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Controller\Dispatcher\Standard.php(288):
Zend_Controller_Action->dispatch('addrecordAction')
#6 D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Controller\Front.php(936):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http),
Object(Zend_Controller_Response_Http))
#7
D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Application\Bootstrap\Bootstrap.php(77):
Zend_Controller_Front->dispatch()
#8 D:\_FRAMEWORKS_\_ZF_TRUNK\library\Zend\Application.php(303):
Zend_Application_Bootstrap_Bootstrap->run()
#9 D:\Projects\zf-ims\public\index.php(26): Zend_Application->run()
#10 {main} 
  
thanks alot for ur fast replies, helped me alot! :)


Matthew Weier O'Phinney-3 wrote:
> 
> -- 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/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Custom-Validators-tp23354806p23355896.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to