2010年3月9日星期二

[fw-mvc] Re: [fw-general] Validator not working

-First try to var_dump the validators of the element to see if you validator is properly registered.
-Verify if you are calling isValid on the form after adding the validator.
-Verify if the value is not empty, maybe empty isAllowed
-Verify if earlier validators have breakChainOnFailure set to false, if they break the chain, your validator never gets called if an earlier validator returns false

-Bart

Op 9-3-2010 10:13, Jigal sanders schreef:

ello Everyone,

I am trying to get my UniqueEmail validator working but it seems that my validator is never triggered.

This is my form:

 class EventManager_Form_User_Base extends SF_Form_Abstract{   public function init(){        $this->addElementPrefixPath(           'EventManager_Validate',           APPLICATION_PATH . '/modules/eventManager/models/validate',           'validate'           );        (...)       $this->addElement('text','usr_email', array(           'filters'   => array('StringTrim', 'StringToLower'),           'valdators' => array(               array('StringLength',true,array(3,128)),               array('EmailAddress'),               array('UniqueEmail', false, array(new EventManager_Model_User())),           ),           'required'  =>  true,           'label'     => 'email',       ));       (...)   }   

}

And here is my validator

 class EventManager_Validate_UniqueEmail extends Zend_Validate_Abstract{        const EMAIL_EXISTS = 'emailExists';        protected $_messageTemplates = array(           Self::EMAIL_EXISTS => 'Email "%value%" already exists in our system',       );        public function __constructs(EventManager_Model_User $model){            $this->_model = $model;        }       public function isValid($value,$context = null){            $this->_setValue($value);           $currentUser = isset($context['usr_id']) ? $this->_model->getUserById($context['user_id']) : null;           $user = $this->_model->getUserByEmail($value, $currentUser);           if(null === $user){               return true;           }           $this->_error(self::EMAIL_EXISTS);           return false;       }    }   

When I add the line

 var_dump($value); exit;    

in the first line of my isValid() function and then run my form. then the code just runs but seems not to get into my validator.

I am running zf 1.10.1 any idea's / suggestions?


J sanders

--
Bart McLeod
Space Web
Middenlaan 47
6865 VN Heveadorp
The Netherlands
t +31(0)26 3392952
m 06 51 51 89 71
@ info@spaceweb.nl
www.spaceweb.nl
zce logozce PHP 5 logo zce Zend Framework logo

Bart McLeod is a Zend Certified Engineer.

Click to verify!

没有评论: