First of all, thanks to Simon for providing an example. I had no idea about that $context thing, so thanks for the heads up.
And thanks Matthew for considering adding this. I found the issue on the tracker and cast my vote. I'll follow your example and use addDescription for now. /Jens Ljungblad Matthew Weier O'Phinney-3 wrote: > > -- pakmannen <[EMAIL PROTECTED]> wrote > (on Wednesday, 18 June 2008, 04:03 PM -0700): >> Just started working with Zend_Form and I'm liking it so far. One thing >> I'm >> wondering about though, which came up when I was working with a login >> form >> using Zend_Auth. It would be great if there was a method for adding error >> messages to an element with a public method. > > Couple of notes. First, I wrote up an example for exactly this situation > on my blog some months ago: > > > http://weierophinney.net/matthew/archives/165-Login-and-Authentication-with-Zend-Framework.html > > In that article, I suggest using the form's Description along with a > Description decorator for displaying an "invalid credentials" message. > > Second, there have been requests for an error message mutator in > Zend_Form/Zend_Form_Element, and I hope to have time to do this for the > 1.6 release. > >> This example should explain it >> pretty well: >> >> // Execute authentication and save the result >> $result = Zend_Auth::getInstance()->authenticate($adapter); >> >> // Handle authentication results >> switch ($result->getCode()) { >> case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND: >> $form->getElement('username')->addError('The supplied username is >> invalid'); >> break; >> case Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS: >> $form->getElement('username')->addError('The supplied username is >> not unique'); >> break; >> case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID: >> $form->getElement('password')->addError('The supplied password is >> invalid'); >> break; >> case Zend_Auth_Result::SUCCESS: >> $this->_helper->Redirector('index', 'index'); >> break; >> } >> >> Thank you for an otherwise excellent component! > > -- > Matthew Weier O'Phinney > Software Architect | [EMAIL PROTECTED] > Zend Framework | http://framework.zend.com/ > > -- View this message in context: http://www.nabble.com/Zend_Form%3A-adding-error-messages-to-elements-tp17993924p18010725.html Sent from the Zend Framework mailing list archive at Nabble.com.
