It may be better to extend Zend_Validate_Db_NoRecordExists to create your own "UniqueUsername" validator. This would allow you to pre-define the table/field properties and add a new method like setCurrentUsername(). The validator could then check if the username had been changed and, if so, query the database for a duplicate. Otherwise, if the username was not changed it would immediately return true (valid) and not need to hit the database. -- Hector Sent from Temecula, California, United States
On Mon, Aug 3, 2009 at 8:39 AM, holografix . <[email protected]> wrote: > Hi > Did you tried Zend_Validate_Db_RecordExists ? > > cheers > holo > > > > 2009/8/3 flow <[email protected]> > >> >> Hi holo, >> >> thanks for you answer. >> This works fine when creating a new user, but when editing an existing >> user >> you always get 'Username already exists!'. >> Thats why I'm using the different validators in new and editAction. >> Greets, >> B. >> >> >> >> holografix wrote: >> > >> > Hi >> > >> > I use the validator in the form: >> > >> > //... >> > >> > ->addValidator( >> > 'Db_NoRecordExists', true, >> > array('table' => 'users', 'field' => 'username', 'messages' => >> array( >> > 'recordFound' => 'Username already exists!' >> > ) >> > ) >> > ) >> > >> > >> > Cheers >> > holo >> > >> > >> > 2009/8/3 flow <[email protected]> >> > >> >> >> >> Hi, >> >> >> >> I want to use Zend_Validate_Db_NoRecordExists to check if a username >> >> already >> >> exists. >> >> Actually I set the validator in the edit and in the new Action of the >> >> userController. >> >> >> >> Validator in newAction() >> >> >> >> // Set validator >> >> $db_lookup_validator = new >> Zend_Validate_Db_NoRecordExists('user', >> >> 'username'); >> >> $form->username->addValidator($db_lookup_validator); >> >> >> >> >> >> Validator in editAction() >> >> >> >> // Set validator >> >> $db_lookup_validator = new >> Zend_Validate_Db_NoRecordExists('user', >> >> 'username', array('field' => 'id', 'value' => $id)); >> >> $form->username->addValidator($db_lookup_validator); >> >> >> >> >> >> >> >> I want to know if this is the correct way to do this? >> >> Or is there a way to get the hole validation thing in the user form? >> >> >> >> Thank you very much, >> >> greets B. >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/Zend_Validate_Db_NoRecordExists-tp24787176p24787176.html >> >> Sent from the Zend Framework mailing list archive at Nabble.com. >> >> >> >> >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/Zend_Validate_Db_NoRecordExists-tp24787176p24792564.html >> Sent from the Zend Framework mailing list archive at Nabble.com. >> >> >
