On Thu, 2008-02-14 at 10:20 -0800, robstar wrote: [...]
> I'm not really sure how to process this list in the template.. or how > it gets stored for the correct field. Suppose I have this code in > clean(): > > rc = 0 > if 'captcha' in self.cleaned_data: > if not self.cleaned_data['imghash'] == sha.new(SALT > +self.cleaned_data['captcha']).hexdigest(): > error_list.append("Captcha error!") > rc = 1 > raise forms.ValidationError(_(u'CAPTCHA error!')) > > > if 'password1' in self.cleaned_data and 'password2' in > self.cleaned_data: > if self.cleaned_data['password1'] != > self.cleaned_data['password2']: > error_list.append("Password mismatch!") > rc = 1 > raise forms.ValidationError(_(u'You must type the same > password each time')) > > if rc: > raise forms.ValidationError(error_list) > > return self.cleaned_data > > How does this function know to associate 'Captcha error' with > captcha ? and how do I reference it in the template? Any ValidationErrors raised by Form.clean() (or a method with the same name in a subclass) are put into the special "all" part of the error dictionary. This means they aren't associated with any particular field. If you want to associate them with a field inside of Form.clean(), you're going to have to manually modify self._errors (where "self" is your Form subclass), rather than raising ValidationError. That's the only way you can put an error against two fields simultaneously if you really want to go down that path. As to how to work with the errors dictionary once it exists, have a search for the word "errors" in the newforms documentation. Also realise that if you're using something like form.as_p in your template, that will automatically put the error for field FOO alongside field FOO when it prints the form. Malcolm -- A conclusion is the place where you got tired of thinking. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---