Oliver, form['fieldname'] returns a Field class object. To add an error to that you want to do form.errors['fieldname'] = ['Your list of errors messages'].
If you also want to preserve other possible errors you'll want to us form.errors.setdefault('fieldname', []).append('Your error here.') instead. The setdefault is because errors is a dictionary of lists, but if it is empty you have to initialize it with an empty list for that field, but if it is not you want to append to the errors list. I've also used this method to create general errors that are displayed somewhere else without using the standard form errors display. For example, if you do form.errors['general'] = ['Some general error'] then you can use form.errors.general to display those errors in your template. There may be better/cleaner ways to tie into the error messages mechanism for newforms, but I tried both ways, raising ValidationError in an overridden clean function, or just adding to the errors lists and it seemed easier/cleaner to do just add to the errors dictionary. If you want to preserve the as_ul and as_p formatting that is expected in some templates for the errors you'll want to use "from django.newforms.util import ErrorList" and replace where I've used a list with ErrorList. Now you can call in your template, forms.errors.fieldname.as_ul etc. Brandon On Apr 4, 11:10 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Thanks for your comments. I've had a dig around in the code for > newforms -- and it appears that to make an error, it raises > django.newforms.util.ValidationError -- the only thing I don't get is > how it binds this to a form field -- any ideas as all it seems to take > is one argument -- the error message...? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---